numpy.matmul_numpy.matmul()用于矩阵乘法| 使用Python的线性代数

本文介绍了Python的Numpy库中的numpy.matmul()函数,该函数用于矩阵乘法。遵循矩阵乘法的基本规则,即矩阵A(MxN)与矩阵B(NxP)相乘时,结果矩阵的维度为MxP。示例展示了如何使用numpy.matmul()进行矩阵运算。
摘要由CSDN通过智能技术生成

numpy.matmul

Prerequisite: Linear Algebra | Defining a Matrix

先决条件: 线性代数| 定义矩阵

Numpy is the library of function that helps to construct or manipulate matrices and vectors. The function numpy.matmul() is a function used for matrix multiplication. The example of matrix multiplication is shown in the figure.

Numpy是一个功能库,可帮助构造或操纵矩阵和向量。 函数numpy.matmul()是用于矩阵乘法的函数。 图中显示了矩阵乘法的示例。

There is a fundamental rule followed by every matrix multiplication, If the matrix A (with dimension MxN) is multiplied by matrix B (with dimensions NxP) then the resultant matrix (AxB or AB) has dimension MxP. In other words, the number of columns in matrix A and the number of rows in matrix B must be equal.

每个矩阵相乘都有一个基本规则,如果矩阵A (维数为MxN )乘以矩阵B (维数为NxP ),则所得矩阵( AxBAB )的维数为MxP 。 换句话说,矩阵A中的列数和矩阵B中的行数必须相等。

NumPy

Syntax:

句法:

    matrix_Multiplication = numpy.matmul(Matrix_1, Matrix_2)

Input parameters: Matrix_1, Matrix_2 the two matrices (following the above-mentioned rule).

输入参数: Matrix_1 , Matrix_2两个矩阵(遵循上述规则)。

Python代码演示用于矩阵乘法的numpy.matmul()示例 (Python code to demonstrate example of numpy.matmul() for matrix multiplication)

# Linear Algebra Learning Sequence 
# Matrix Multiplication using 
# function in numpy library

import numpy as np

# Defining two matrices
V1 = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
V2 = np.array([[965,2413,78],[223,356,500],[312,66,78]])

print("--Matrix A--\n", V1)
print("\n\n--Matrix B--\n", V2)

# using function np.matmul( )
AB = np.matmul(V1, V2)

print("\n\n--Matrix Multiplication AB-- \n", AB)

Output:

输出:

--Matrix A--
 [[  1   2   3]
 [  2   3   5]
 [  3   6   8]
 [323 623 823]]


--Matrix B--
 [[ 965 2413   78]
 [ 223  356  500]
 [ 312   66   78]]


--Matrix Multiplication AB-- 
 [[   2347    3323    1312]
 [   4159    6224    2046]
 [   6729    9903    3858]
 [ 707400 1055505  400888]]


翻译自: https://www.includehelp.com/python/numpy-matmul-for-matrix-multiplication.aspx

numpy.matmul

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值