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)
"""
[[ 1 0 1 0]
[-1 2 0 1]
[ 1 0 4 1]
[-1 -1 2 0]]
"""
# 方法二
B = np.mat('1 0 0 0;0 1 0 0;-1 2 1 0;1 1 0 1')
print(B)
"""
[[ 1 0 0 0]
[ 0 1 0 0]
[-1 2 1 0]
[ 1 1 0 1]]
"""
# 1、matrix函数
# np.matrix()
# 3.bmat函数:通过分块矩阵创建大矩阵
A = np.mat([[1, 1], [1, 1]])
B = np.mat([[2, 2], [2, 2]])
C = np.mat([[3, 3], [3, 3]])
D = np.mat([[4, 4], [4, 4]])
big_mat = np.bmat([[A, B], [C, D]])
print(big_mat)
"""
[[1 1 2 2]
[1 1 2 2]
[3 3 4 4]
[3 3 4 4]]
"""
# 矩阵运算
A = np.mat([[1, 1], [1, 1]])
B = np.mat([[2, 2], [3, 3]])
print(A*3)
"""
[[3 3]
[3 3]]
"""
print(A+B)
"""
[[3 3]
[4 4]]
"""
print(A*B)
"""
[[5 5]
[5 5]]
"""
# 矩阵对应元素相乘
print(np.multiply(A,B))
"""
[[2 2]
[3 3]]
"""
矩阵特有的属性: