So, I have a numpy 2D array (256,256) containing values from 0 to 10, which is essentially an image. I need to remove the values 0 and set them to NaN so that I can build an array using a specific library (APLpy). However, whenever I try to change all the values of 0, some other values change, in some cases up to 100 times their original value (I don’t know why).
The code I use is:
for index, value in np.ndenumerate(tex_data):
if value == 0:
tex_data[index] = 'NaN'
where tex_data is the data array from which I need to remove zeros. Unfortunately, I can't just use a mask for values that I don't need, since APLpy will not use masked arrays, as far as I can tell.
In any case, can I set the values 0 to NaN without changing other values in the array?
source
share