1.创建mxn的矩阵
import numpy as np
from numpy import *x = np.array([[2,1],[1,2],[2,2])#创建了一个3x2的数组
x = np.mat(x)#将数组转化为矩阵
2.数组与矩阵的转化
from numpy import *
import numpy as np#数组转化为矩阵
matrix = np.mat(array)#矩阵转化为数组
array = matrix.A
3.矩阵的运算
#矩阵相加减
matrix = matrix1 ± matrix2#矩阵点乘:对应位置的元素进行相乘,常数与矩阵也是属于点乘
matrix = np.multiply(matrix1,matrix2)
matrix = constant*matrix1
matrix = np.multiply(constant,matrix1)#矩阵叉乘:行列相乘
matrix = matrix1.dot(martrix2)
matrix = np.dot(matrix1,matrix2)
matrix = matrix1*matrix2例:
x0 = np.mat(np.around([[1.2,2],[2,1]],decimals = 3))
x1 = np.mat(np.around([[2],[1]],decimals = 3))#decimals表示取多少位小数
x0_x1 = x0.dot(x1)
print(x0_x1)结果:
[[4.4][5. ]]
4.矩阵的逆
matrix_inv = matrix.I