3D numpy 配列があり、別の要素の条件付きテストに基づいて特定の要素を変更したいと考えています。(アプリケーションは、RGBA 画像配列の「アルファ」を変更して、3D pyqtgraph 画像の透明度を操作することです - 理想的にはかなり高速である必要があります)。
a= np.ones((2,4,5),dtype=np.int) #create a ones array
a[0,0,0] = 3 #change a few values
a[0,2,0] = 3
a[1,2,0] = 3
print(a)
>>>[[[3 1 1 1 1]
[1 1 1 1 1]
[3 1 1 1 1]]
[[1 1 1 1 1]
[1 1 1 1 1]
[3 1 1 1 1]]]
今、条件付きで最低次元 (??) の最初の要素をテストし、結果に基づいて最後の要素を変更したいと考えています。
if a[0,:,:] > 1: #this does not work - for example only - if first element > 1
a[3,:,:]=255 #then change the last element in the same dimension to 255
print(a) #this is my idealized result
>>>[[[3 1 1 1 255]
[1 1 1 1 1]
[3 1 1 1 255]]
[[1 1 1 1 1]
[1 1 1 1 1]
[3 1 1 1 255]]]