标签:imp nump lis 矩阵 port list 列表 rom pre
将数组或者矩阵转换成列表,如下:
>>> 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
但是当矩阵是一维的时候,就不同了,所以一维矩阵经常会有tolist()[0]
>>>a1=[1,2,3] #列表 >>>a2=array(a1) >>> a2 array([1, 2, 3]) >>>a3=mat(a1) >>> a3 matrix([[1, 2, 3]]) >>> a4=a2.tolist() >>> a4 [1, 2, 3] >>> a5=a3.tolist() >>> a5 [[1, 2, 3]] >>> a6=(a4==a5) >>> a6 False >>> a7=(a4 is a5[0]) >>> a7 True
标签:imp nump lis 矩阵 port list 列表 rom pre
原文地址:https://www.cnblogs.com/yang520ming/p/8861684.html