mindspore.Tensor.item
- Tensor.item(index=None)[source]
Get the item at the specified index of the tensor.
Note
Tensor.item returns a Tensor scalar instead of a Python scalar.
- Parameters
index (Union[None, int, tuple(int)]) – The index in Tensor. Default: None.
- Returns
A Tensor scalar, dtype is the same with the original Tensor.
- Raises
ValueError – If the length of the index is not equal to self.ndim.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([[1,2,3],[4,5,6]], dtype=np.float32)) >>> x = x.item((0,1)) >>> print(x) 2.0