关于nparray和list的转换,可以用np.array和tolist函数,但这两个函数并不会改变原本变量的类型,如下所示。

>>> a = [1,2,3]
>>> type(a)
<class 'list'>
>>> import numpy as np
>>> np.array(a)
array([1, 2, 3])
>>> type(a)
<class 'list'>
>>> b = np.array(a)
>>> type(b)
<class 'numpy.ndarray'>
>>> b.tolist()
[1, 2, 3]
>>> type(b)
<class 'numpy.ndarray'>
>>> c = b.tolist()
>>> type(c)
<class 'list'>
>>> b = b.tolist()
>>> b
[1, 2, 3]
>>> type(b)
<class 'list'>
>>> exit()

如果想得到改变类型之后的变量,需要给一个赋值。

https://blog.csdn.net/github_38575699/article/details/108109249