torch.bucketize
function bucketize(input: Tensor, boundaries: Tensor, options?: BucketizeOptions): Tensorfunction bucketize(input: Tensor, boundaries: Tensor, out_int32: boolean, right: boolean, options?: BucketizeOptions): TensorReturns the indices of the buckets to which each value in the input belongs.
Parameters
inputTensor- Input tensor
boundariesTensor- 1D sorted tensor of bucket boundaries
optionsBucketizeOptionsoptional- Optional settings for bucketize
Returns
Tensor– Tensor of bucket indicesExamples
const values = torch.tensor([0.5, 1.5, 2.5, 3.5]);
const boundaries = torch.tensor([1, 2, 3]);
torch.bucketize(values, boundaries); // [0, 1, 2, 3]