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 ),则所得矩阵( AxB或AB )的维数为MxP 。 换句话说,矩阵A中的列数和矩阵B中的行数必须相等。

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