Several matrix multiplication Np.dot in Python, Np.multiply, *

Source: Internet
Author: User

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, *

Related Article

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.