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}")
相关推荐
不枯石5 天前
Python实现点云法向量各种方向设定
python·计算机视觉·numpy
njxiejing7 天前
Python NumPy安装、导入与入门
开发语言·python·numpy
胡耀超7 天前
5、Python-NumPy科学计算基础
开发语言·人工智能·python·深度学习·numpy
程序员奈斯8 天前
Python深度学习:NumPy数组库
python·深度学习·numpy
君名余曰正则8 天前
机器学习实操项目01——Numpy入门(基本操作、数组形状操作、复制与试图、多种索引技巧、线性代数)
线性代数·机器学习·numpy
一车小面包9 天前
人工智能中的线性代数总结--简单篇
人工智能·numpy
__Bolide__16 天前
【不说废话】pytorch张量相对于numpy数组的优势
人工智能·pytorch·numpy
胖祥17 天前
NumPy/PyTorch/C char数组内存排布
c语言·pytorch·numpy
云烟成雨TD17 天前
NumPy 2.x 完全指南【三十二】通用函数(ufunc)之数学运算函数
python·机器学习·numpy
深兰科技17 天前
柳州市委常委、统战部部长,副市长潘展东率队首访深兰科技集团新总部,共探 AI 赋能制造大市与东盟合作新局
人工智能·beautifulsoup·numpy·pyqt·matplotlib·pygame·深兰科技