numpy.searchsorted with 2D array numpy.searchsorted with 2D array numpy numpy

numpy.searchsorted with 2D array


You can searchsorted on the ravel/flattened array:

In [11]: np.searchsorted(a.ravel(), b)Out[11]: array([3, 6])

You can then use divmod on the result (which gets the row and column):

In [12]: divmod(np.searchsorted(a.ravel(), b), a.shape[1])Out[12]: (array([0, 1]), array([3, 1]))