digitize#
- class brainunit.math.digitize(x, bins, right=False, **kwargs)#
Return the indices of the bins to which each value in input array belongs.
right
order of bins
returned index i satisfies
Falseincreasing
bins[i-1] <= x < bins[i]Trueincreasing
bins[i-1] < x <= bins[i]Falsedecreasing
bins[i-1] > x >= bins[i]Truedecreasing
bins[i-1] >= x > bins[i]If values in x are beyond the bounds of bins, 0 or
len(bins)is returned as appropriate.- Parameters:
x (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – Input array to be binned. Prior to NumPy 1.10.0, this array had to be 1-dimensional, but can now have any shape.bins (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – Array of bins. It has to be 1-dimensional and monotonic.right (
bool) – Indicating whether the intervals include the right or the left bin edge. Default behavior is (right==False) indicating that the interval does not include the right edge. The left bin end is open in this case, i.e., bins[i-1] <= x < bins[i] is the default behavior for monotonically increasing bins.
- Returns:
indices – Output array of bin indices, same shape as
x.- Return type:
Array
Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> x = jnp.array([0.5, 1.5, 2.5]) >>> bins = jnp.array([0.0, 1.0, 2.0, 3.0]) >>> u.math.digitize(x, bins) Array([1, 2, 3], dtype=int32)