mindspore.Tensor.searchsorted

Tensor.searchsorted(v, side='left', sorter=None)[source]

Finds indices where elements should be inserted to maintain order.

Parameters
  • v (Union[int, float, bool, list, tuple, Tensor]) – Values to insert into the tensor.

  • side (str, optional) – If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of the tensor). Default: ‘left’.

  • sorter (Union[int, float, bool, list, tuple, Tensor]) – 1-D optional tensor of integer indices that sort the tensor into ascending order. They are typically the result of argsort. Default: None.

Returns

Tensor, array of insertion points with the same shape as v.

Raises

ValueError – If argument for side or sorter is invalid.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> x = Tensor(np.array([1, 2, 3, 4, 5]))
>>> print(x.searchsorted(3))
2