我的问题如下:
import sympy as sp
p = sp.symbols('p')
I_p = sp.Identity(p)
C = sp.BlockMatrix([[I_p, I_p], [I_p, -I_p]])
Sigma_1 = sp.MatrixSymbol('Sigma_1', p, p)
Sigma_2 = sp.MatrixSymbol('Sigma_2', p, p)
Sigma = sp.BlockMatrix([[Sigma_1, Sigma_2], [Sigma_2, Sigma_1]])
C_Sigma_C_transpose = C * Sigma * C.T
print(C_Sigma_C_transpose)
## Matrix([
## [I, I],
## [I, -I]])*Matrix([
## [Sigma_1, Sigma_2],
## [Sigma_2, Sigma_1]])*Matrix([
## [I, I],
## [I, -I]])
结果与预期输出不符。我该如何纠正?
不要使用
BlockMatrix
使它们成为正则矩阵。然后将执行操作。
C = sp.Matrix([[I_p, I_p], [I_p, -I_p]])
Sigma = sp.Matrix([[Sigma_1, Sigma_2], [Sigma_2, Sigma_1]])
# the @ symbol is for matrix multiplication, but * will work
C_Sigma_C_transpose = C@[email protected]
print(C_Sigma_C_transpose )
# Matrix([[2*Sigma_1 + 2*Sigma_2, 0], [0, 2*Sigma_1 - 2*Sigma_2]])
以 LaTeX 格式(来自 Jupyter Notebook):