Numpy创建矩阵
矩阵的创建
1.使用 mat 函数创建矩阵: matr1 = np.mat(“1 2 3; 4 5 6; 7 8 9”)
2.使用 matrix 函数创建矩阵:matr2= np.matrix([[1,2,3], [4,5,6], [7,8,9]])
3.使用 bmat 函数合成矩阵:np.bmat (“arr1 arr2; arr1 arr2”)
import numpy as np
# 一、创建矩阵
# 1.mat函数
#方法一:
A = np.mat([[1,0,1,0],[-1,2,0,1],[1,0,4,1],[-1,-1,2,0]])
print(A)
#方法二:
B = np.mat('1 0 0 0;0 1 0 0; -1 2 1 0;1 1 0 1')
print(B)
# 1.matrix函数与方法一相同
# np.matrix
# 3.bmat函数:通过分块矩阵创建大矩阵。
A = np.mat([[1,1],[1,1]])
B = np.mat([[2,2],[2,2]])
C