Below is the one I coded. The problem here is I have values 1, 2, and 3 in the A matrix and hence at the output A has all the values 1.
The result I expect is:
A = np.matrix([[1, 2, 2, 1],
[1, 1, 3, 1],
[1, 1, 1, 3]]).
Any help is appreciated. Sorry for my poor writing. Thank you!
A = np.matrix([[1, 15, 23, 2], [3, 2, 56, 7], [2, 6, 8, 25]])
bound = np.array([1, 15, 25, 56])
for i in range(3, 0, -1):
A[np.logical_and(bound[i - 1] <= A, A <= bound[i])] = i
numpy.searchsorted?np.searchsorted(bound, A, side='left')1maps to1, why15also maps to1? shouldn't it be2? Since there's a15inbound?np.searchsorted(bound, A, side='right')to see if it gives what you need.