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
aandvare Quantities,vis converted to the unit ofabefore searching.- Parameters:
a (
Union[Array,ndarray,number,bool, saiunit.Quantity]) – Sorted input array.v (
Union[Array,ndarray,number,bool, saiunit.Quantity]) – Values to insert intoa.side (
str) – If'left', the first suitable index is returned. Default is'left'.sorter (
Optional[Array]) – Indices that sortainto 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)