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