Multiplication between arrays created with NumPy in Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.