# bucketize¶

paddle. bucketize ( x, sorted_sequence, out_int32=False, right=False, name=None ) [source]

This API is used to find the index of the corresponding 1D tensor sorted_sequence in the innermost dimension based on the given x.

Parameters
• x (Tensor) – An input N-D tensor value with type int32, int64, float32, float64.

• sorted_sequence (Tensor) – An input 1-D tensor with type int32, int64, float32, float64. The value of the tensor monotonically increases in the innermost dimension.

• out_int32 (bool, optional) – Data type of the output tensor which can be int32, int64. The default value is False, and it indicates that the output data type is int64.

• right (bool, optional) – Find the upper or lower bounds of the sorted_sequence range in the innermost dimension based on the given x. If the value of the sorted_sequence is nan or inf, return the size of the innermost dimension. The default value is False and it shows the lower bounds.

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

Tensor（the same sizes of the x）, return the tensor of int32 if set `out_int32` is True, otherwise return the tensor of int64.

Examples

```import paddle

sorted_sequence = paddle.to_tensor([2, 4, 8, 16], dtype='int32')
x = paddle.to_tensor([[0, 8, 4, 16], [-1, 2, 8, 4]], dtype='int32')
print(out1)
# Tensor(shape=[2, 4], dtype=int64, place=CPUPlace, stop_gradient=True,
#        [[0, 2, 1, 3],
#         [0, 0, 2, 1]])
print(out2)
# Tensor(shape=[2, 4], dtype=int64, place=CPUPlace, stop_gradient=True,
#        [[0, 3, 2, 4],
#         [0, 1, 3, 2]])
out3 = x.bucketize(sorted_sequence)
print(out3)
# Tensor(shape=[2, 4], dtype=int64, place=CPUPlace, stop_gradient=True,
#        [[0, 2, 1, 3],
#         [0, 0, 2, 1]])
out4 = x.bucketize(sorted_sequence, right=True)
print(out4)
# Tensor(shape=[2, 4], dtype=int64, place=CPUPlace, stop_gradient=True,
#        [[0, 3, 2, 4],
#         [0, 1, 3, 2]])
```