How to calculate the matrix in Python is multiplied by elements???

Source: Internet
Author: User

1 # multiply-by-element multiplication of two identical-dimensional matrices 2 def Matelementmul (): 3     A=mat ([[1,2,3],[4,5,6]]); 4     B=mat ([[2,2,3],[2,4,1]]); 5     C=array (a) *array (b); 6     C=Mat (c); 7     return C;

The two matrices must be transformed into arrays, then multiplied, and the arrays converted to matrices;

Calculation Result:

1 >>> c=matelementmul ()2 >>> C3 Matrix ([[2,  4,  9], 4         [8,  6]]) 5

Note: The basic type of 1.MATLAB is a matrix, and the base type of numpy is more than one array, and the matrix is considered a subclass of array. The index of 2.MATLAB starts at 1, while NumPy starts from 0.

How to calculate the matrix in Python is multiplied by elements???

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.