mindspore.Tensor.tolist

mindspore.Tensor.tolist()[源代码]

将Tensor转为列表,如果输入是Tensor scalar,将会返回Python标量。

返回:

列表或者Python标量。

支持平台:

Ascend GPU CPU

样例:

>>> 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