numpy.dot example

文章目录

  • [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}")
相关推荐
TechEdu2026061 天前
[人工智能]Python07:NumPy Selection:详细实践指南
人工智能·numpy
TechEdu2026061 天前
[人工智能]Python09:numpy.random.Statistics统计实战指南
人工智能·numpy
TechEdu2026061 天前
[人工智能]Python10:NumPy.random.Algebra 随机代数实战指南
人工智能·numpy
TechEdu2026063 天前
[人工智能]Python08:NumPy 检查与诊断
人工智能·numpy
TechEdu2026064 天前
[人工智能]Python06:NumPy 数组操作详解
人工智能·numpy
Xiu Yan11 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
醇氧11 天前
Git 合并冲突与`__pycache__` 的恩怨情仇
python·numpy·fastapi
Xiu Yan12 天前
Python 数据分析:Pandas Series 零基础入门教程
python·jupyter·pycharm·numpy·pandas
lpfasd12314 天前
配置文件格式对比 与 AI Coding 的选择逻辑
python·flask·numpy
jzshmyt15 天前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy