I have a big 2-dimensional array which I access by indexes. I want to update only the values of the indexed array which are not zero.
arrayx = np.random.random((10,10))
Let's say I have indexes (this is just example, the actual indexes are generated by separate process):
idxs = np.array([[4],
[5],
[6],
[7],
[8]]), np.array([[5, 9]])
Given these indexes, this should work, but it doesn't.
arrayx[idxs]
array([[0.7 , 0.1 ],
[0.79, 0.51],
[0. , 0.8 ],
[0.82, 0.32],
[0.82, 0.89]], dtype=float16)
// note from editor: '<>' is equivalent to '!='
// but I agree that '>' 0 is more correct
// mask = mapx[idxs] <> 0 // original
mask = arrayx[idxs] > 0 // better
array([[ True, True],
[ True, True],
[False, True],
[ True, True],
[ True, True]])
arrayx[idxs][mask] += 1
However, this does not update the array. How can I solve this?