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}")
相关推荐
老歌老听老掉牙15 小时前
SymPy 矩阵到 NumPy 数组的全面转换指南
python·线性代数·矩阵·numpy·sympy
key_Go1 天前
7.Ansible自动化之-实施任务控制
python·ansible·numpy
科大饭桶2 天前
昇腾AI自学Day2-- 深度学习基础工具与数学
人工智能·pytorch·python·深度学习·numpy
pan0c232 天前
数据处理与统计分析 —— numpy入门
python·numpy
芥末章宇4 天前
Jetson NX Python环境搭建:使用APT轻松安装NumPy, scikit-learn, OpenCV
python·numpy·scikit-learn
猫头虎4 天前
用 Python 写你的第一个爬虫:小白也能轻松搞定数据抓取(超详细包含最新所有Python爬虫库的教程)
爬虫·python·opencv·scrapy·beautifulsoup·numpy·scipy
姜—姜4 天前
数据分析总结
数据挖掘·数据分析·numpy·pandas·matplotlib·jieba·seaborn
码界筑梦坊7 天前
108-基于Python的中国古诗词数据可视化分析系统
python·信息可视化·数据分析·django·毕业设计·numpy
WSSWWWSSW7 天前
Numpy科学计算与数据分析:Numpy文件操作入门之数组数据的读取和保存
开发语言·python·数据挖掘·数据分析·numpy
唐叔在学习8 天前
Python NumPy入门指南:数据处理科学计算的瑞士军刀
python·数据分析·numpy·数组操作·python数据处理