How does python perform matrix operations

The method of python matrix operation:

1、 Matrix multiplication

 a1=mat([1,2]);   
 a2=mat([[1],[2]]);
 a3=a1*a2 #1*Multiply the matrix of 2 by 2*1 matrix, get 1*Matrix of 1
 a3
matrix([[5]])

2、 Multiply the corresponding elements of the matrix

 a1=mat([1,1]);
 a2=mat([2,2]);
 a3=multiply(a1,a2)
 a3
matrix([[2,2]])

multiply() function: multiply the corresponding positions of the array and matrix, and the output is the same as the size of the multiplied array/matrix

3、 Matrix dot product

 a1=mat([2,2]);
 a2=a1*2
 a2
matrix([[4,4]])

4、 Matrix inversion

 a1=mat(eye(2,2)*0.5)
 a1
matrix([[0.5,0.],[0.,0.5]])
 a2=a1.I #Find matrix([[0.5,0],[0,0.5]])Inverse matrix
 a2
matrix([[2.,0.],[0.,2.]])

5、 Matrix transpose

 a1=mat([[1,1],[0,0]])
 a1
matrix([[1,1],[0,0]])
 a2=a1.T
 a2
matrix([[1,0],[1,0]])

6、 Calculate the sum of each column and row

 a2=a1.sum(axis=0) #Column sum, here is 1*Matrix of 2
 a2
matrix([[7,6]])
 a3=a1.sum(axis=1) #Line sum, here is 3*Matrix of 1
 a3
matrix([[2],[5],[6]])
 a4=sum(a1[1,:]) #Calculate the sum of all the columns in the first row, here is a value
 a4
5   # Row 0: 1+1; Line 2: 2+3; row 3: 4+2

Content expansion:

numpy matrix operations

(1) Matrix dot product: m=multiply(A,B)

(2) Matrix multiplication: m1=a*b m2=a.dot(b)

(3) Matrix inversion: aI

(4) Matrix transpose: aT

So far, this article on how python performs matrix operations is introduced. For more related python methods of matrix operations, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support ZaLou more in the future. Cn!

Recommended Posts

How does python perform matrix operations
How does Python output integers
How does python output backslashes
How does python update packages
How does Python list update value
How does python change the environment
How does python call java classes
How does python import dependency packages
How does python enter interactive mode
How does Python generate xml files
How does python determine prime numbers
How does python improve the calculation speed
How does python call its own function
How does Python handle the json module
How does python distinguish return and yield
How does Python call cmd using OS modules
How does Python store data to json files
How to perform continuous multiplication calculation in python
How does python call the key of a dictionary
How does python get input examples from the keyboard
How python was invented
How does python handle the program cannot be opened
How does python judge the module installation is complete
How Python parses XML
How long does it take to learn python by myself?
How to comment python code
How Python converts string case
How to learn python quickly
How to uninstall python plugin
Does Python support multiple inheritance?
How Python implements FTP function
How to understand python objects
How to use python tuples
Explain how python references package package