python .tolist() 将数组或者矩阵转换成list

python .tolist() 将数组或者矩阵转换成list

from numpy import *
a1 = [[1,2,3],[4,5,6]] #列表
a2 = array(a1) #数组
a2
'''
array([[1, 2, 3],
   [4, 5, 6]])
'''
a3 = mat(a1) #矩阵
a3
'''
matrix([[1, 2, 3],
    [4, 5, 6]])
'''
a4 = a2.tolist()
a4
#[[1, 2, 3], [4, 5, 6]]
a5 = a3.tolist()
a5
#[[1, 2, 3], [4, 5, 6]]
a4 == a5
#True
原文地址:https://www.cnblogs.com/cgmcoding/p/13589317.html