mindspore.ops.bucketize

mindspore.ops.bucketize(input, boundaries, *, right=False)[source]

Return the indices of the buckets to which each element in the input tensor belongs. If right is False, the left boundary is open. For each element x in input, the returned index satisfies the following rules:

\[\begin{split}\begin{cases} boundaries[i-1] < x <= boundaries[i], & \text{if right} = False\\ boundaries[i-1] <= x < boundaries[i], & \text{if right} = True \end{cases}\end{split}\]

Warning

Starting after version 2.9.0, an optional keyword argument out_int32 will be added. The signature will change to mindspore.ops.bucketize(input, boundaries, *, out_int32=False, right=False). This change is backward-compatible; behavior is unchanged when out_int32 is not specified.

Parameters
  • input (Tensor) – The input tensor.

  • boundaries (list) – A sorted ascending list of bucket boundary values.

Keyword Arguments

right (bool, optional) – If False, gets the lower bound index for each value in input from boundaries; If True, gets the upper bound index instead. Default: False.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([[3, 6, 9], [3, 6, 9]])
>>> boundaries = [1., 3., 5., 7., 9.]
>>> output = mindspore.ops.bucketize(input, boundaries, right=True)
>>> output
Tensor(shape=[2, 3], dtype=Int32, value=
[[2, 3, 5],
 [2, 3, 5]])