矩阵初始化
支持matlab语句初始化,支持narray和array初始化。
>>> import numpy as np
>>> M = np.matrix("1 2 3;4 5 6;7 8 9")
>>> M
matrix([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
矩阵相乘
支持点乘
>>> import numpy as np
>>> M = np.matrix("1 2 3;4 5 6;7 8 9")
>>> M
matrix([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> N = np.matrix(np.eye(3))
>>> N
matrix([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> M*N
matrix([[ 1., 2., 3.],
[ 4., 5., 6.],
[ 7., 8., 9.]])
矩阵转置和逆
>>> M.T
matrix([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
>>> M.I
matrix([[ -4.50359963e+15, 9.00719925e+15, -4.50359963e+15],
[ 9.00719925e+15, -1.80143985e+16, 9.00719925e+15],
[ -4.50359963e+15, 9.00719925e+15, -4.50359963e+15]])
矩阵的数组形式
>>> M.A
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> M.A1
array([1, 2, 3, 4, 5, 6, 7, 8, 9])