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}")
相关推荐
一百天成为python专家2 天前
数据可视化
开发语言·人工智能·python·机器学习·信息可视化·numpy
赴3352 天前
Numpy 库 矩阵数学运算,点积,文件读取和保存等
人工智能·算法·numpy·random·dot
海哥编程3 天前
Python 数据分析(一):NumPy 基础知识
python·数据分析·numpy
赴3355 天前
numpy库 降维,矩阵创建与元素的选取,修改
numpy·flatten
paid槮5 天前
Python进阶第三方库之Numpy
开发语言·python·numpy
星期天要睡觉5 天前
NumPy库使用教学,简单详细。
numpy
lxmyzzs6 天前
【bug】Yolo11在使用tensorrt推理numpy报错
yolo·计算机视觉·bug·numpy
WBluuue6 天前
数学建模:运筹优化类问题
python·算法·数学建模·numpy·动态规划·matplotlib·图论
@MMiL7 天前
Python 中常见的数据管理高效方法
python·numpy·pandas·matplotlib
赴3357 天前
Numpy库,矩阵形状与维度操作
开发语言·python·矩阵·numpy·resize·reshape