[] Data Analysis Data Mining & computing matrix

. 1  Import numpy AS NP
 2  
. 3  # create a matrix 
. 4 m1 = np.mat ([[. 1, 2], [. 1, 2 ]])
 . 5  Print ( " m1: \ n- " , m1)
 . 6  Print ( " type of m1 : \ n- " , type (M1))
 . 7  
. 8  # matrix multiplication with the number 
. 9 m2 = 2 * M1
 10  Print ( " m2: \ n- " , m2)
 . 11  Print ( " type m2,: \ n- " , type (M2))
 12 is  
13 is  # adding matrix subtraction -> isotype matrix
14 m2 = np.mat ([[0,. 1], [0,. 1 ]])
 15  Print ( " m2: \ n- " , m2)
 16  Print ( " Type m2,: \ n- " , type (m2))
 . 17  
18 is RES1 = M1 + M2
 . 19 RES2 = M1 - M2
 20 is  Print ( " : addition / subtraction of results \ n- " , RES1, " \ n- " , RES2)
 21 is  
22 is  # matrix multiplication of the matrix 
23  # left = the right column of a matrix row 
24 RES = M1 * M2
 25 RES =np.matmul (M1, M2)
 26 is RES = np.dot (M1, M2)
 27  Print ( " matrix multiplication results: \ n- " , RES)
 28  
29  # matrix multiplication array, the array will be automatically converted to further matrix multiplication 
30 ARR = np.array ([[0,. 1], [0,. 1 ]])
 31 is RES = M1 * ARR # possible error in certain cases, can not recommended 
32 RES = NP .matmul (M1, ARR)
 33 is RES = np.dot (M1, ARR)
 34 is  
35  # matrix multiplication list, the list will automatically be converted to the matrix and then multiplied by 
36 Li = [[0,. 1], [0, . 1 ]]
 37 [ RES = M1 * Li   # possible error in certain cases, can not recommended 
38 is RES =np.matmul (M1, Li)
 39 RES = np.dot (M1, Li)
 40  
41 is  Print ( " multiplication results: \ n- " , RES)
 42 is  
43 is  # If a matrix multiplication when multiplying API list , then the list will first be converted to the matrix and then multiplied by 
44 is L1 = [[. 1, 2], [. 1, 2 ]]
 45 L2 = [[0,. 1], [0,. 1 ]]
 46 is  # RES = L1 * by not l2 # 
47 RES = np.matmul (L1, L2)
 48 RES = np.dot (L1, L2)
 49  Print ( " multiplication results: \ n- " , RES)
 50  
51 is  # Another way is multiplied - multiplying element corresponding position - isotype by multiplying 
52= RES np.multiply (M1, M2)
 53 is  Print ( " corresponding to the position of the element matrix multiplication: \ n- " , RES)
 54 is  
55 of arr1 np.array = ([[. 1, 2], [. 1, 2 ]])
 56 is arr2 is np.array = ([[. 1, 2], [. 1, 2 ]])
 57 is RES = np.multiply (of arr1, arr2 is)
 58  Print ( " corresponding to the position of the element of the array multiplied: \ n- " , RES)
 59 L1 = [[. 1, 2], [. 1, 2 ]]
 60 L2 = [[. 1, 2], [. 1, 2 ]]
 61 is RES = np.multiply (L1, L2)
 62 is  Print ( " corresponding to the list multiplying the position of the element: \ n- " , RES)
63 is  
64  # attribute matrix of 
65 M1 = np.mat ([[. 1, 2], [. 1, 2 ]])
 66 M1 = np.mat ([[. 1, 2,. 3], [. 1, 2,. 4 ] ])
 67  Print ( " M1: \ n- " , M1)
 68  Print ( " M1 type: \ n- " , type (M1))
 69  Print ( " ~ " * 60 )
 70  Print ( " M1 transposed: \ the n- " , m1.T)
 71  Print ( " M1 inverse matrix: \ the n- " , m1.I) # matrix inverse matrix must have in order to use 
72 Print ( " m1 conjugate transpose matrix: \ n- " , m1.H)
 73 is  
74  # view matrix array is - can be converted to utilize view matrix array 
75  Print ( " view matrix m1: \ n- " , m1.A)
 76  Print ( " type view of matrix m1: \ n- " , type (m1.A))

Guess you like

Origin www.cnblogs.com/Tree0108/p/12115455.html