Python numpy array and matrix exponentiation

Source: Internet
Author: User
Tags lua

Python numpy array and matrix exponentiationprogramming language Waitig 1 years ago (2017-04-18) 1272 ℃ Baidu has included 0 reviews

The exponentiation of an array of arrays (* * is the exponentiation operator) is the exponentiation of each element, while matrix matrices are multiplied by the matrix and must therefore be square.

Arrays and matrices of 2*3

>>> FromNumPyImport *>>> Import operator>>>A=Array([[1,2,3],[4,5,6]])>>>Aarray([[1, 2, 3], [4, 5, 6]])>>>M=Mat(A)>>>Mmatrix([[1, 2, 3], [4, 5, 6]])>>>A** 2Array([[ 1, 4, 9], [16, 25, 36]])>>>M** 2Traceback (Most recent callLast): File "<stdin>",Line1, Inch <Module> File "D:\anaconda\lib\site-packages\numpy\matrixlib\defmatrix.py",Line356, Inch__pow__return Matrix_power ( self, Other) file , line  173, in Matrix_power raise valueerror  ( "input must be a square array") Valueerror:input must Be a square array>>>             

(The mat () function converts an array into matrix)

Arrays and matrices of 3*3

>>>A=Array([[1,2,3],[4,5,6],[7,8,9]])>>>Aarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])>>>M=Mat(A)>>>Mmatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])>>>A** 2Array([[ 1, 4, 9], [16, 25, 36], [49, 64, 81]])>>>M** 2matrix ( [[ 30, 36, 42],< Span class= "PLN" > [ 66, 81, 96),  [102,  126, 150]])    

Python numpy array and matrix exponentiation

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.