注:每一步可能依赖于上一步import的模块
一、数组
1,用numpy对数组进行运算
from numpy import array
mm=array((1, 1, 1))
pp=array((1,...>>> from numpy import shape
>>> shape(mm)
(1, 3)
>>> shape(ss.T)
(3, 1)
5,矩阵元素相乘:mm的每个元素和ss的每个元素相乘...显示矩阵的行列数:
>>> jj = mat([[1, 2, 3], [8, 8, 8]])
>>> shape(jj)
(2, 3)
事实证明多维数组和矩阵基本相同:
>>> qq =...array([[1, 2, 3], [8, 8, 8]])
>>> shape(qq)
(2, 3)
取出矩阵第二行的元素:用行号和冒号
>>> jj[1, :]
matrix([[8, 8..., 8]])
取出第一行的第1列和第2列的元素:
>>> jj[0, 0:2]
matrix([[1, 2]])
注: 范围0:2表示从 0 取到 1
关于NumPy更多
http://docs.scipy.org