TypeError:iteration over a 0-d tensor

参考numpy官方文档

https://numpy.org/doc/stable/reference/generated/numpy.ndarray.tolist.html

当0-D的数组转换为list时,必须使用tolist(),不能使用list()

The base case for this recursion is a 0D array:

>>> a = np.array(1)
>>> list(a)
Traceback (most recent call last):
  ...
TypeError: iteration over a 0-d array
>>> a.tolist()
1

你可能感兴趣的:(numpy,python,深度学习)