mindspore.ops.searchsorted

View Source On Gitee
mindspore.ops.searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, sorter=None)[source]

Return the position indices where the elements can be inserted into the input tensor to maintain the increasing order of the input tensor.

Parameters
  • sorted_sequence (Tensor) – The input tensor. If sorter not provided, it must contain a increasing sequence on the innermost dimension.

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

Keyword Arguments
  • out_int32 (bool, optional) – Whether the output datatype will be mindspore.int32. if False , the output datatype will be mindspore.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) – An index sequence sorted in ascending order along the innermost dimension of sorted_sequence , which is used together with the unsorted sorted_sequence . CPU and GPU only support None. Default None .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> sorted_sequence = mindspore.tensor([1, 2, 2, 3, 4, 5, 5])
>>> values = mindspore.tensor([2])
>>> mindspore.ops.searchsorted(sorted_sequence, values)
Tensor(shape=[1], dtype=Int64, value= [1])