python实现矩阵共轭和共轭转置
(以IDLE上操作为例。完整代码在下方)
创建一个矩阵:
>>> import numpy as np
>>> e = np.mat("1 2+3j;3 4+5j")
或使用第二种方法创建矩阵(不推荐):
>>> e = [[1, 2+3j],[3, 4+5j]]
>>> e = np.matrix(a)
输出矩阵:
>>> e
matrix([[1.+0.j, 2.+3.j],
[3.+0.j, 4.+5.j]])
使用 conjugate() 函数实现共轭:
>>> e.conjugate()
matrix([[1.-0.j, 2.-3.j],
[3.-0.j, 4.-5.j]])
共轭就是对一个复数的虚部求反。共轭转置就是转置后再求共轭。python里复数用 j 来代表数学中的复数 i 。
求共轭转置:
>>> e.T.conjugate()
matrix([[1.-0.j, 2.-0.j]
[0.-2.j, 6.-5.j]])
完整代码:
import numpy as np
# 使用mat() 创建矩阵以 ; 隔开每一行,句号隔开行中的列。
e = np.mat("1 2+3j;3 4+5j")
print("原矩阵:\n", e)
# 共轭矩阵
print("共轭矩阵:\n", e.conjugate())
# 共轭转置
print("共轭转置: \n", e.T.conjugate())