mindspore.mint.searchsorted

mindspore.mint.searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, sorter=None)[source]

Return the position indices such that after inserting the values into the sorted_sequence, the order of innermost dimension of the sorted_sequence remains unchanged.

Parameters
  • sorted_sequence (Tensor) – The input tensor. It must contain a monotonically increasing sequence on the innermost dimension.

  • values (Tensor) – The value that should be inserted.

Keyword Arguments
  • out_int32 (bool, optional) – Output datatype. If True , the output datatype will be int32; if False , the output datatype will be int64. Default: False .

  • right (bool, optional) – Search Strategy. If True , return the last suitable index found; if False , return the first such index. Default: False .

  • side (str, optional) – the same as right but preferred. "left" corresponds to False for right and "right" corresponds to True for right. An error will be reported if this parameter is set to "left" while right is True. Default: None .

  • sorter (Tensor, optional) – if provided, a tensor matching the shape of the unsorted sorted_sequence containing a sequence of indices that sort it in the ascending order on the innermost dimension and type must be int64. Default: None .

Returns

Tensor containing the indices from the innermost dimension of sorted_sequence such that, if insert the corresponding value in the values Tensor, the order of sorted_sequence would be preserved, whose datatype is int32 if out_int32 is True , otherwise int64, and shape is the same as the shape of values.

Raises
  • ValueError – If the dimension of sorted_sequence isn't 1 and all dimensions except the last dimension of sorted_sequence and values are different.

  • ValueError – If sorted_sequence value is a scalar.

  • ValueError – If values is a scalar when sorted_sequence dimension is not 1.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> sorted_sequence = Tensor(np.array([[0, 1, 3, 5, 7], [2, 4, 6, 8, 10]]), mindspore.float32)
>>> values = Tensor(np.array([[3, 6, 9], [3, 6, 9]]), mindspore.float32)
>>> output = mint.searchsorted(sorted_sequence, values)
>>> print(output)
[[2 4 5]
 [1 2 4]]