mindspore.ops.intopk
- mindspore.ops.intopk(x1, x2, k)[source]
Determines whether the targets are in the top k predictions.
- Parameters
x1 (Tensor) – A 2D Tensor defines the predictions of a batch of samples with float16 or float32 data type.
x2 (Tensor) – A 1D Tensor defines the labels of a batch of samples with int32 data type. The size of x2 must be equal to the first dimension of x1. The values of x2 can not be negative and must be equal to or less than index of x1’s second dimension.
k (int) – Specifies the number of top elements to be used for computing precision along the last dimension.
- Returns
Tensor has 1 dimension of type bool and the same shape with x2. For labeling sample i in x2, if the label in the first k predictions for sample i is in x1, then the value is True, otherwise False.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> x1 = Tensor(np.array([[1, 8, 5, 2, 7], [4, 9, 1, 3, 5]]), mindspore.float32) >>> x2 = Tensor(np.array([1, 3]), mindspore.int32) >>> output = ops.intopk(x1, x2, 3) >>> print(output) [ True False]