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}\]- Parameters
- Keyword Arguments
right (bool, optional) – if
False
, gets the lower bound index for each value in input from boundaries; IfTrue
, 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]])