When using array, the operator * is used to calculate the quantity product (point multiplication), and the function dot () is used to calculate the cross product (cross-multiply).
When using matrix, the operator * is used to calculate cross product, and the function multiply () is used to calculate the quantity product.
Here's when you use array:
1. Definition of matrix multiplication in the same linear algebra: Np.dot ()
Np.dot (A, B): For a two-dimensional matrix, the definition of matrix multiplication in the true sense of the Matrix, and of the same linear algebra. For a one-dimensional matrix, the inner product of both is computed.
2. Multiply the corresponding elements element-wise product:np.multiply (), or *
In Python, there are 2 ways to multiply the corresponding elements, one is np.multiply () and the other is *. Both of these effects are the same.
Please look at the code:
1 #!/usr/bin/env Python32 #-*-Coding:utf-83 4 ImportNumPy as NP5 6X = Np.array ([[1,2],[3,4]])7Y = Np.array ([[5,6],[7,8]])8 9A1 =Np.dot (x, y)Ten Print('Np.dot (x, y) =\n', A1) One AA2 =np.multiply (x, y) - Print('np.multiply (x, y) =\n', A2)
Operation Result:
Np.dot (x, y) = [[+] [50]]np.multiply (x, y) = [[5] [32]]x*y=] [[5 12] [21 32]]
Several matrix multiplication Np.dot in Python, Np.multiply, *