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}")
相关推荐
__Bolide__6 天前
【不说废话】pytorch张量相对于numpy数组的优势
人工智能·pytorch·numpy
胖祥7 天前
NumPy/PyTorch/C char数组内存排布
c语言·pytorch·numpy
云烟成雨TD7 天前
NumPy 2.x 完全指南【三十二】通用函数(ufunc)之数学运算函数
python·机器学习·numpy
深兰科技8 天前
柳州市委常委、统战部部长,副市长潘展东率队首访深兰科技集团新总部,共探 AI 赋能制造大市与东盟合作新局
人工智能·beautifulsoup·numpy·pyqt·matplotlib·pygame·深兰科技
麻雀无能为力11 天前
python自学笔记14 NumPy 线性代数
笔记·python·numpy
麻雀无能为力12 天前
python 自学笔记13 numpy数组规整
笔记·python·numpy
CodeCraft Studio15 天前
Excel处理控件Aspose.Cells教程:使用Python将 Excel 转换为 NumPy
python·excel·numpy·aspose·数据表格·aspose.cells·excel文档格式转换
R-G-B21 天前
OpenCV Python——Numpy基本操作(Numpy 矩阵操作、Numpy 矩阵的检索与赋值、Numpy 操作ROI)
python·opencv·numpy·numpy基本操作·numpy 矩阵操作·numpy 矩阵的检索与赋值·numpy 操作roi
计算机毕设-小月哥21 天前
完整源码+技术文档!基于Hadoop+Spark的鲍鱼生理特征大数据分析系统免费分享
大数据·hadoop·spark·numpy·pandas·计算机毕业设计
老歌老听老掉牙22 天前
SymPy 矩阵到 NumPy 数组的全面转换指南
python·线性代数·矩阵·numpy·sympy