$$tr(A\times B\times C)=tr(A\times C\times B)=tr(B \times A \times C)$$
一系列矩阵相乘,循环它的各个元素,最终得到的结果迹是相同的。
import numpy as np
x = np.random.randint(0, 10, (3, 3))
y = np.random.randint(0, 10, (3, 3))
z = np.random.randint(0, 10, (3, 3))
print(np.trace(x @ y @ z))
print(np.trace(x @ z @ y))
print(np.trace(z @ x @ y))
print(np.trace(y @ z @ x))
原文地址:https://www.cnblogs.com/weiyinfu/p/10690158.html
时间: 2024-10-17 15:59:11