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