mindspore.numpy.digitize
- mindspore.numpy.digitize(x, bins, right=False)[source]
Returns the indices of the bins to which each value in input array belongs. If values in x are beyond the bounds of bins, 0 or
len(bins)
is returned as appropriate.- Parameters
x (Union[int, float, bool, list, tuple, Tensor]) – Input array to be binned.
bins (Union[list, tuple, Tensor]) – Array of bins. It has to be 1-dimensional and monotonic.
right (boolean, optional) – 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
Tensor of ints, output array of indices, of same shape as x.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.]) >>> bins = np.array([0, 5, 10, 15, 20]) >>> inds = np.digitize(x, bins) >>> print(inds) [1 3 3 4 5]