Indexes of elements
Question:
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?
Answers:
The function searchsorted provides exactly the functionality you need.
C = np.searchsorted(A, B)
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?
The function searchsorted provides exactly the functionality you need.
C = np.searchsorted(A, B)