mindspore.ops.Bucketize

class mindspore.ops.Bucketize(boundaries)[source]

Bucketizes ‘input’ based on ‘boundaries’.

Parameters

boundaries (list[float]) – A sorted list of floats gives the boundary of the buckets, and no default value.

Inputs:
  • input (Tensor) - A tensor containing the search value(s).

Outputs:

Tensor, with the same shape as the input, and data type is int32.

Raises
Supported Platforms:

GPU CPU

Examples

>>> class Bucketize(nn.Cell):
...     def __init__(self, boundaries):
...         super().__init__()
...         self.bucketize = ops.Bucketize(boundaries=boundaries)
...     def construct(self, input):
...         return self.bucketize(input)
>>> input = Tensor(np.array([[3, 6, 9], [3, 6, 9]]).astype(np.int32))
>>> boundaries = list(np.array([1., 3., 5., 7., 9.]))
>>> net = Bucketize(boundaries)
>>> output = net(input)
>>> print(output)
[[2 3 5]
 [2 3 5]]