I have an array (2000 * 2000) with floats and I want to classify the numbers.
So all numbers between 10 and 20 should be replaced with 15 and numbers between 20 – 60 should be replaced with 40 and so on.
I wrote something looping over all the rows and columns with a couple of if statements… but it takes forever to run over large arrays. Does anybody know how to speed things up?
for a in range(grid.shape[0]): #grid is an array
for b in range(grid.shape[1]):
for c in range(len(z)):
if z[c][0] <= grid[a][b] < z[c][1]: # z is a list containing [lower,upper,replace_value]
grid[a][b]=z[c][2]
Would something like this work for you?