I am using a digital elevation model as an array, and I want to create a new array with only the pixels below a certain value. I tried using a for loop.
Here is the operation with simpler data :
import numpy as np
array1 = array2 = np.arange(9).reshape(3,3)
array2 = array2.astype("float") #np.nan doesn't work with integers
for row in array2:
for item in row:
if item > 3.0:
item=np.nan
print(np.array_equal(array1,array2))
The arrays remain equal after the loop is over. Do you know why the values won't be replaced?