AlexM
AlexM

Reputation: 45

Indexes of elements

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?

Upvotes: 0

Views: 25

Answers (1)

7shoe
7shoe

Reputation: 1506

The function searchsorted provides exactly the functionality you need.

C = np.searchsorted(A, B)

Upvotes: 1

Related Questions