将Tensor转为列表,如果输入是Tensor scalar,将会返回Python标量。
列表或者Python标量。
Ascend GPU CPU
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