array

Array Utilities

Array

searchsorted

quantecon.util.array.searchsorted(a, v)[source]

Custom version of np.searchsorted. Return the largest index i such that a[i-1] <= v < a[i] (for i = 0, v < a[0]); if a[n-1] <= v, return n, where n = len(a).

Deprecated since version 0.11.0: Use np.searchsorted(a, v, side=’right’) instead.

Parameters:
andarray(float, ndim=1)

Input array. Must be sorted in ascending order.

vscalar(float)

Value to be compared with elements of a.

Returns:
scalar(int)

Largest index i such that a[i-1] <= v < a[i], or len(a) if no such index exists.

Notes

This routine is jit-compiled by Numba in nopython mode.

Examples

>>> import numpy as np
>>> from quantecon.util import searchsorted
>>> a = np.array([0.2, 0.4, 1.0])
>>> searchsorted(a, 0.1)
0
>>> searchsorted(a, 0.4)
2
>>> searchsorted(a, 2)
3