欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【线代】矩阵转置性质及代码证明

程序员文章站 2022-03-05 20:29:37
...

矩阵转置的定义

定义: 把矩阵A的行换成同序列数的列得到一个新矩阵,叫做A的转置矩阵 ,记作ATA^T

矩阵转置的性质

  1. (AT)T=A(A^T)^T=A
import numpy as np
A = np.random.randint(0, 100, [3, 3])
print((A.T).T == A)
[OUT]:
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]]
  1. (A+B)T=AT+BT(A+B)^T=A^T+B^T
import numpy as np
A = np.random.randint(0, 100, [3, 3])
B = np.random.randint(0, 100, [3, 3])
print((A+B).T==A.T+B.T)
[OUT]:
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]]
  1. (λA)T=λAT(\lambda A)^T=\lambda A^T
import numpy as np
A = np.random.randint(0, 100, [3, 3])
lambda_ = 3.14
print((lambda_*A).T == lambda_*A.T)
[OUT]:
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]]
  1. (AB)T=BTAT(AB)^T=B^TA^T
import numpy as np
A = np.random.randint(0, 100, [2, 4])
B = np.random.randint(0, 100, [4, 2])
print(([email protected]).T == B.[email protected].T)
[OUT]:
[[ True  True]
 [ True  True]]
  1. 若方阵A满足AT=AA^T=A,则称A为对称矩阵。A=(aij)nA=(a_{ij})_n为对称矩阵的充要条件是aij=aji(i,j=1,2, ,n)a_{ij}=a_{ji}(i,j=1,2,\cdots,n)
import numpy as np


def symmetric(shape):
    matrix = np.triu(np.random.randint(0, 100, shape))
    matrix += matrix.T-np.diag(matrix.diagonal())
    return matrix


A = symmetric([3, 3])
print(A.T == A)
[OUT]:
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]]
相关标签: 线性代数