I have numpy array: A = np.array([1,3,5,7,9]) and B = np.array([3,3,3,5,5,5])
I want to have array C - which is index B in A. C = np.array([1,1,1,2,2,2])
How I can do it?
CodePudding user response:
The function searchsorted provides exactly the functionality you need.
C = np.searchsorted(A, B)