searchsorted

Contents

searchsorted#

class saiunit.math.searchsorted(a, v, side='left', sorter=None, *, method='scan', **kwargs)#

Find indices where elements should be inserted to maintain order.

When both a and v are Quantities, v is converted to the unit of a before searching.

Parameters:
  • a (Union[Array, ndarray, number, bool, saiunit.Quantity]) – Sorted input array.

  • v (Union[Array, ndarray, number, bool, saiunit.Quantity]) – Values to insert into a.

  • side (str) – If 'left', the first suitable index is returned. Default is 'left'.

  • sorter (Optional[Array]) – Indices that sort a into ascending order.

  • method (Optional[str]) – Algorithm selection. Default is 'scan'.

Returns:

indices – Insertion points with the same shape as v.

Return type:

Union[Array, saiunit.Quantity]

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> a = jnp.array([1.0, 2.0, 3.0, 4.0])
>>> u.math.searchsorted(a, jnp.array([2.5]))
Array([2], dtype=int32)