Multiplication between arrays created with NumPy in Python
Import NumPy as NP
When an array of numpy modules is multiplied, there are two ways: the first is the Matrix, and the second is the multiplication of each.
Use the Np.dot () function when you need to multiply in matrix form.
Matrices and matrices:
A = Np.array ([[1,2,3],[4,5,6],[7,8,9]])
c = a.copy ()
The result of a*c is that each element in a and C is multiplied in sequence, as a 3x3 matrix
The result of Np.dot (A, c) is that A and C are multiplied by a matrix, which is a 3x3 matrix
Matrices and vectors:
A = Np.array ([[1,2,3],[4,5,6],[7,8,9]])
b = Np.array ([+])
A.shape # (3,3)
B.shape # (3,)
A*b # Array ([[[1,4,9],[4,10,18],[7,16,27]]), each number of each column in a is multiplied by each number in each column in B, that is, a multiple of each column in a (same as the addition)
B*a #这个结果与a *b is the same.
b = b.t
B.shape # Even if the B transpose, B is still (3,), B is the row vector or column vector, is to see when the specific use of the matrix on the left or right, will automatically transform
Np.dot (A, B) # array ([14, 32, 50]), at which point B is treated as a 3x1 column vector, resulting in (3,)
Np.dot (b, a) # array ([30, 36, 42]), at which point B is treated as a 1x3 line vector, resulting in (3,)
Multiplication between arrays created with NumPy in Python
Original: http://www.cnblogs.com/Rambler1995/p/5581582.html
Multiplication between arrays created with NumPy in Python