私は2つの配列を持っています:
-image
はNxN配列、
-indices
はMx2配列で、最後の次元は有効なインデックスをに格納しますimage
。
image
でそのインデックスが出現するたびに 1 を追加しindices
ます。
numpy.add.at(image, indices, 1)
への2次元インデックス付けを実行できないことを除いて、トリックを行う必要があるようですimage
:
image = np.zeros((5,5), dtype=np.int32)
indices = np.array([[1,1], [1,1], [3,3]])
np.add.at(image, indices, 1)
print(image)
結果:
[[0 0 0 0 0]
[4 4 4 4 4]
[0 0 0 0 0]
[2 2 2 2 2]
[0 0 0 0 0]]
望ましい結果:
[[0 0 0 0 0]
[0 2 0 0 0]
[0 0 0 0 0]
[0 0 0 1 0]
[0 0 0 0 0]]