How to Search Sorted NumPy Array to Find Indices


In this example, we will learn how to search the sorted NumPy array to find the indices where the multiple values should be inserted to maintain order in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4, 5, 6, 7])

idx = np.searchsorted(n, [3, 6, 9])

print(idx)

Output:

[2 5 7]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments