mindspore.ops.SearchSorted
- class mindspore.ops.SearchSorted(dtype=mstype.int64, right=False)[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.
Warning
This is an experimental API that is subject to change or deletion.
Refer to
mindspore.ops.searchsorted()
for more details.- Parameters
dtype (mindspore.dtype, optional) – The specified type of output tensor. Optional values are:
mstype.int32
andmstype.int64
. Default value:mstype.int64
.right (bool, optional) – Search Strategy. If
True
, return the last suitable index found; ifFalse
, return the first such index. Default:False
.
- Inputs:
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.
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
. CPU and GPU can only use default values
- Outputs:
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
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> searchsorted = ops.SearchSorted() >>> 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 = searchsorted(sorted_sequence, values) >>> print(output) [[2 4 5] [1 2 4]]