文章目录
- [1. 左行右列](#1. 左行右列)
- [2. numpy.dot](#2. numpy.dot)
1. 左行右列
假设有两个矩阵A,P 对于矩阵A来说,
- AP矩阵中,P在A的右边,那么对于矩阵A来说是对矩阵A进行列变换
- PA矩阵中,P在A的左边,那么对于矩阵A来说是对矩阵A进行行变换
A = [ 1 2 3 4 5 6 7 8 9 ] ; P = [ 1 0 0 0 0 1 0 1 0 ] ; \begin{equation} A=\begin{bmatrix} 1&2&3\\\\ 4&5&6\\\\ 7&8&9\end{bmatrix}; P=\begin{bmatrix} 1&0&0\\\\ 0&0&1\\\\ 0&1&0\end{bmatrix}; \end{equation} A= 147258369 ;P= 100001010 ; - AP,将第二列和第三列互换
A P = [ 1 2 3 4 5 6 7 8 9 ] [ 1 0 0 0 0 1 0 1 0 ] = [ 1 3 2 4 6 5 7 9 8 ] ; \begin{equation} AP=\begin{bmatrix} 1&2&3\\\\ 4&5&6\\\\ 7&8&9\end{bmatrix}\begin{bmatrix} 1&0&0\\\\ 0&0&1\\\\ 0&1&0\end{bmatrix}=\begin{bmatrix} 1&3&2\\\\ 4&6&5\\\\ 7&9&8\end{bmatrix}; \end{equation} AP= 147258369 100001010 = 147369258 ; - PA,将第二行和第三行互换
P A = [ 1 0 0 0 0 1 0 1 0 ] [ 1 2 3 4 5 6 7 8 9 ] = [ 1 2 3 7 8 9 4 5 6 ] \begin{equation} PA=\begin{bmatrix} 1&0&0\\\\ 0&0&1\\\\ 0&1&0\end{bmatrix}\begin{bmatrix} 1&2&3\\\\ 4&5&6\\\\ 7&8&9\end{bmatrix}=\begin{bmatrix} 1&2&3\\\\ 7&8&9\\\\ 4&5&6\end{bmatrix} \end{equation} PA= 100001010 147258369 = 174285396
2. numpy.dot
- numpy.dot(A,P)--> AP 列变换
python
import numpy as np
if __name__ == "__main__":
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# A=[[1 2 3]
# [4 5 6]
# [7 8 9]]
P = np.array([[1, 0, 0], [0, 0, 1], [0, 1, 0]])
# P=[[1 0 0]
# [0 0 1]
# [0 1 0]]
# AP 列变换
column_permutation = np.dot(A, P)
# column_permutation=
# [[1 3 2]
# [4 6 5]
# [7 9 8]]
# PA 行变换
row_permutation = np.dot(P, A)
# row_permutation=
# [[1 2 3]
# [7 8 9]
# [4 5 6]]
print(f"A={A}")
print(f"P={P}")
print(f"column_permutation=\n{column_permutation}")
print(f"row_permutation=\n{row_permutation}")