I have two numpy Array with the same SHAPEs. One with values and one with "zones". I need to find max value and index of the value in valuearr which overlap zone 3 in zonearr:
import numpy as np
valuearr = np.array([[10,11,12,13],
[21,22,23,24],
[31,32,33,34],
[41,42,43,44]])
zonearr = np.array([ [0,0,1,1],
[0,0,1,1],
[3,3,0,0],
[3,3,0,0]])
Im trying:
valuearr[np.argwhere(zonearr==3)].max()
44
When it should be 42.
To get index i try
ind = np.unravel_index(np.argmax(valuearr[np.argwhere(zonearr==3)], axis=None), valuearr.shape)
Which of course doesnt work since max value is not 44 and also give error:
builtins.ValueError: index 19 is out of bounds for array with size 16
print(valuearr[zonearr==3].max())gives42. Maybe make sure that yourzonearris ofdtype=np.int.