python列表转换为矩阵

#创建列表
>>> l=[] //然后用列表的insert函数将系数项插入到列表中去,最后将列表转换为矩阵
insert(“插入位置”,插入的内容对象)
>>> l.insert(0,[9,52,381])
>>> l
[[9, 52, 381]]
>>> l.insert(1,[52,381,3017])
>>> l
[[9, 52, 381], [52, 381, 3017]]
>>> l.insert(2,[381,3017,25317])
>>> l
[[9, 52, 381], [52, 381, 3017], [381, 3017, 25317]]
>>> a=np.mat(l)#这里将列表转换为矩阵
>>> a
matrix([[ 9, 52, 381],
[ 52, 381, 3017],
[ 381, 3017, 25317]])

>>> l=[]
>>> l.insert(0,[32])
>>> l.insert(1,[147])
>>> l.insert(2,[1025])
>>> l
[[32], [147], [1025]]
>>> b=np.mat(l)#将列表转换为矩阵
>>> b
matrix([[ 32],
[ 147],
[1025]])

猜你喜欢

转载自blog.csdn.net/haodawei123/article/details/88286775