klyn.math.NDArray.digitize
method
public digitize(notnull edges as NDArray<Double>, right as Boolean = false) as NDArray<Long>
Description

Assigns every element to a monotone sequence of bin boundaries. Ascending: edges[i-1] <= x < edges[i], reversed when right=true. Descending edges are supported. Output 0/edges.size denotes outside bins; NaN maps after all ascending edges (before all descending edges). Time O(N log B), O(N+B) storage, no source mutation.

Parameters
ParameterDescription
edgesNon-empty finite strictly monotone 1D Double boundaries.
rightInclude the right endpoint rather than the left.
Returns

Long insertion indices with the same shape as the source.

Throws
  • ValueException for invalid boundaries.
  • NullException if edges is null at runtime; statically null arguments are rejected with TypeError.
Example

indices = data.digitize(NDArray<Double>([0.0, 1.0, 2.0]))