mindspore.Tensor.tolist

View Source On Gitee
Tensor.tolist()[source]

Convert a Tensor to List. If the input is Tensor scalar, a Python scalar will be returned.

Returns

List or Python scalar.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> x = ms.Tensor([[1, 2, 3], [4, 5, 6]])
>>> out1 = x.tolist()
>>> print(out1)
[[1, 2, 3], [4, 5, 6]]
>>> out2 = x[0][0].tolist()
>>> print(out2)
1