Reputation: 57
I have an one image array of shape (4, 64, 256)
.
At pixel [63, 0]
I found nan values.
output[:, 63, 0] -----> array([nan, nan, nan, 1.])
So after using output = np.nan_to_num(output)
, succesfully I got:
output[:, 63, 0] -----> array([0., 0., 0., 1.])
Then I am unable to get like this:
output[:, 63, 0] -----> array([0., 0., 1., 1.])
I tried new = output[np.where(output[2, 63, 0] == 0), [2, 63, 0]] = 1
but it gives 1 as output instead of array([0., 0., 1., 1.])
please help me solve this.
Upvotes: 0
Views: 526
Reputation: 66
It depends on what you want to accomplish:
output[2,63,0] = 1
output = np.where(output == 0, 1, output)
(see: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.where.html)output[2,:,:] = np.where(output[2,:,:] == 0, 1, output[2,:,:])
Hope this helps!
Upvotes: 2