multi_dot
可以用于多个矩阵的乘法,而且会根据最少的计算量进行优化。
矩阵相乘的计算量示例:A(10,100) B(100,5)C(5,50)
cost((AB)C) = 10x100x5 + 10x5x50 = 5000 + 2500 = 7500
cost(A(BC)) = 10x100x50 + 100x5x50 = 50000 + 25000 = 75000
用法:
np.linalg.multi_dot([A, B, C, D])
参考:https://numpy.org/doc/1.18/reference/generated/numpy.linalg.multi_dot.html