– Start
[第1集] 矩阵简介
import numpy as np
# 什么是矩阵(matrix)?
a = np.array([ [1, 2],
[3, 4] ])
b = np.array([ [-1, -2],
[-3, -4] ])
# 矩阵加法
c = a + b
print(f'a + b = {c}')
# 矩阵减法
c = a - b
print(f'a - b = {c}')
[第2集] 矩阵乘法(一)
[第3课] 矩阵乘法(二)
import numpy as np
# 定义矩阵
a = np.array([ [1, 2],
[3, 4] ])
b = np.array([ [-1, -2],
[-3, -4] ])
# 矩阵乘法 (行*列)
# [[(1*-1 + 2*-3), (1*-2 + 2*-4)],
# [(3*-1 + 4*-3), (3*-2 + 4*-4)]]
c = a @ b
print(c)
[第4集] 矩阵的逆(一)
import numpy as np
# 单位矩阵(identity matrix)
a = np.identity(3)
b = np.eye(3)
print('单位矩阵')
print(a)
# 逆矩阵(inverse matrix)
c = np.array([ [1, 2],
[3, 4] ])
# 行列式(determinant) = (1*4 - 2*3)
# 伴随矩阵(adjugate of matrix) = np.array([ [4, -2],
# [-3, 1] ])
# 逆矩阵 = 1 / 行列式 * 伴随矩阵
d = np.linalg.inv(c)
print('矩阵 c')
print(c)
print('c 的逆矩阵')
print(d)
# 矩阵 * 逆矩阵 = 单位矩阵
e = c @ d
e = np.round(e, 2)
print('矩阵 * 逆矩阵')
print(e)
– 声 明:转载请注明出处
– Last Updated on 2018-10-22
– Written by ShangBo on 2018-10-22
– End