Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code:

import numpy as np
x=np.array([4,5,6,7,8])
print(np.searchsorted(x,7,side='right'))

Output:

4

What I have tried:

It should give 1 instead of 4 pls tell the reason
Posted

1 solution

Read the documentation: numpy.searchsorted — NumPy v2.0 Manual[^] - it returns 4, this being the index at which to insert your new value 7 in order to maintain a sorted order. i.e., before the 8 ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900