2-2 Numpy- matrix

 1 # !usr/bin/env python
 2 # Author:@vilicute
 3 
 4 import numpy as np
 5 # 矩阵的创建
 6 matr1 = np.mat("4 2 3;4 5 6;7 8 9")
 7 matr2 = np.matrix([[4,5,6],[7,8,9],[1,2,3]])
 8 print("\nmatr1=\n",matr1)
 9 print("\nmatr2=\n",matr2)
10 
11 arr1 = np.eye(3)
12 arr2 = arr1*3
13 arr3 = np.random.randint(0,10,size = [3,3])
14 arr4 = np.random.randint(6,10,size = [3,3])
15 matr3 = np.bmat("arr1 arr3;arr4 arr2")
16 print("\nmatr3=\n",matr3)
17 
18 
19 # 矩阵的运算
20 matr_numul = matr1*4
21 matr_add = matr1 + matr2
22 matr_sub = matr1 - matr2
23 matr_mul = matr1 * matr2
24 matr_multiply = np.multiply(matr1, matr2)
25 print(" \ N by number: \ n " , matr_numul)
 26 is  Print ( " \ n addition: \ n " , matr_add)
 27  Print ( " \ n subtraction: \ n " , matr_sub)
 28  Print ( " \ n multiplied : \ n- " , matr_mul)
 29  Print ( " \ n-multiplied by the corresponding elements: \ n- " , matr_multiply)
 30  
31 is  Print ( " \ n-permutation: \ n- " , matr1.T)
 32  Print ( " \ n-conjugated transpose: \ the n- " , matr1.
H)
33 print( " \ N-inversion: \ n- " , matr1.I)
 34 is  Print ( " \ n-dimensional array of view: \ n- " , matr1.A) 
35 '' ' 36 matr1 = 37 [ [[2. 4. 3] 38 is [ . 5. 6. 4] 39 [. 7. 8. 9]] 40 matr2 = 41 is [[. 4. 5. 6] 42 is [. 7. 8. 9] 43 is [2. 3. 1]] 44 is matr3 = 45 [[4. 1. of 0. The of 0. The. 8. 1.] 46 [0. 5. 3. 3. 1. 0.] 47 [5. 1. 1. 1 0. 0.] 48 [6.8.1 8. 3. 0. 0.] 49 [ 8. 8. 9. 0. 3. 0.] 50 [9 0. 7 0. 7 3.]] 51 multiplication: 52 [[16,812] 53 [16 20 24] 54 [283236]] 55 are added: 56 [[879] 57 [111315] 58 [81012]] 59 subtraction: 60 [[0-3-3] 61 [-3-3-3] 62 [666]] 63 multiplies: 64 [[33 4251] 65 [577287] 66 [93117141]] 67 corresponding element multiplication: 68 [[161,018] 69 [284054] 70 [71627]] 71 transposition: 72 [[447] 73 [258] 74 [369]] 75 conjugate transpose: 76 [[447] 77 [258] 78 [369]] 79 Inversion: 80 [[0.33333333 0.33333333 -0.66666667] 81 [-0.66666667 1.33333333 -1.66666667] 82 [2 0.33333333 -1.33333333]] 83 two-dimensional array of view: 84 [[423] 85 [456] 86 [789] ] 87 '' '

 

Guess you like

Origin www.cnblogs.com/vilicute/p/11605420.html