dpnp.digitize

dpnp.digitize(x, bins, right=False)[source]

Return the indices of the bins to which each value in input array belongs.

For full documentation refer to numpy.digitize.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array to be binned.

  • bins ({dpnp.ndarray, usm_ndarray}) -- Array of bins. It has to be 1-dimensional and monotonic increasing or decreasing.

  • right (bool, optional) -- Indicates whether the intervals include the right or the left bin edge. Default: False.

Returns:

indices -- Array of indices with the same shape as x.

Return type:

dpnp.ndarray

Notes

This will not raise an exception when the input array is not monotonic.

See also

dpnp.bincount

Count number of occurrences of each value in array of non-negative integers.

dpnp.histogram

Compute the histogram of a data set.

dpnp.unique

Find the unique elements of an array.

dpnp.searchsorted

Find indices where elements should be inserted to maintain order.

Examples

>>> import dpnp as np
>>> x = np.array([0.2, 6.4, 3.0, 1.6])
>>> bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0])
>>> inds = np.digitize(x, bins)
>>> inds
array([1, 4, 3, 2])
>>> for n in range(x.size):
...     print(bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]])
...
0. <= 0.2 < 1.
4. <= 6.4 < 10.
2.5 <= 3. < 4.
1. <= 1.6 < 2.5
>>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.])
>>> bins = np.array([0, 5, 10, 15, 20])
>>> np.digitize(x, bins, right=True)
array([1, 2, 3, 4, 4])
>>> np.digitize(x, bins, right=False)
array([1, 3, 3, 4, 5])