searchsorted

Contents

searchsorted#

class brainunit.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 (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Sorted input array.

  • v (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Values to insert into a.

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

  • sorter (Array | None) – Indices that sort a into ascending order.

  • method (str | None) – Algorithm selection. Default is 'scan'.

Returns:

indices – Insertion points with the same shape as v.

Return type:

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)