How to Find Last Index Where Elements Should Be Inserted to Maintain Order


In this example we will show how to search the sorted NumPy array to find the last index where elements 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, 4, side='right')

print(idx)

Output:

4
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments