9951 explained code solutions for 126 technologies

python-numpyHow to use Numpy binary search

import numpy as np

array = np.array([1,2,3,8])
idx = np.searchsorted(array, 5)ctrl + c
import numpy as np

load Numpy module for Python


declare Numpy array


uses binary search to find position to insert specified value in order to keep array sorted


array to search in


value to search insertion position of