mindspore.ops.intopk

查看源文件
mindspore.ops.intopk(x1, x2, k)[源代码]

返回第二个输入tensor中的元素是否存在于第一个输入tensor的前 k 个元素中。

参数:
  • x1 (Tensor) - 二维输入tensor。

  • x2 (Tensor) - 一维输入tensor。须满足 x2.shape[0]=x1.shape[0]

  • k (int) - 前 k 个元素。

返回:

一维的bool类型tensor,与 x2 shape相同。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> x1 = mindspore.tensor([[1, 8, 5, 2, 7], [4, 9, 1, 3, 5]], mindspore.float32)
>>> x2 = mindspore.tensor([1, 3], mindspore.int32)
>>> mindspore.ops.intopk(x1, x2, 3)
Tensor(shape=[2], dtype=Bool, value= [ True, False])