Python numpy M = T @ S @ R @ P @ C
在学习yolov5算法时遇到 M = T @ S @ R @ P @ C ,不知是什么意思,猜测是类似矩阵乘法,于是做个试验验证一下:
import numpy as np
C = np.eye(3)
C[0, 2] = 1.5
C[1, 1] = 2.5
# print(C)
P = np.eye(3)
P[0, 1] = 2
P[1, 2] = 2.5
# print(P)
R = np.eye(3)
R[0, 1] = 2.2
R[2, 0] = 0.5
# print(R)
S = np.eye(3)
S[0, 1] = 1.2
S[2, 0] = 3.5
# print(S)
T = np.eye(3)
T[0, 1] = 2.3
T[2, 0] = 1.3
# print(T)
M = T @ S @ R @ P @ C
print('M')
print(M)
MM = np.matmul(T, np.matmul(S, np.matmul(R, np.matmul(P, C))))
print('MM')
print(MM)
计算结果:
M
[[ 1. 19.25 15.75]
[ 0. 2.5 2.5 ]
[ 5.3 56.8 39.25]]
MM
[[ 1. 19.25 15.75]
[ 0. 2.5 2.5 ]
[ 5.3 56.8 39.25]]
可知此处的@就是np.matmul的意思,但用@更简洁。