1 # Import numpy module 2 Import numpy AS NP . 3 # Create a one-dimensional array . 4 A = np.arange (1,13 ) . 5 Print (A) . 6 # to modify the shape of one-dimensional arrays (4,3-) . 7 A = A .reshape (4,3-) # form a two dimensional array . 8 Print (a) . 9 # using the index 10 # acquiring a third row . 11 Print (a [2 ]) 12 is # acquires the second row and third column 13 is Print (a [ 1] [2 ]) 14 15 # microtome of [row slicing, sectioning row] [start: stop: step, start: stop: step] 16 # Get all rows in all columns . 17 Print (A [:,:]) 18 is # Get all rows section columns, all rows of the second column . 19 Print (A [:,. 1 ]) 20 is # Get all rows section columns, all rows first and second column 21 is Print (A [:, 0: 2 ]) 22 is # acquisition section row, the column, obtaining all the columns odd rows 23 is Print (A [2 :: ,:]) 24 # acquisition of rows, column, obtaining odd lines, first and second column 25 Print (A [:: 2,0: 2 ]) 26 is 27 # coordinate acquiring [row, column] 28 # acquires row 2 3 29 Print (A [. 1 ] [2 ]) 30 Print(A [1,2 ]) 31 is # acquired simultaneously in different rows in different columns, 2 rows and 3 columns acquisition, and a 3 row 32 Print (A [1,2], A [2 ] [0]) 33 is Print (NP .Array (a [1,2], a [2 ] [0])) 34 is # using a coordinate 35 Print (a [(1,2), (2 , 0)]) 36 37 [ # a negative index 38 is Print ( ' last line ' ) 39 Print (A [-1 ]) 40 Print ( " line reverse " ) 41 is Print (A [:: -. 1 ]) 42 is Print (A [:: -. 1, :: -. 1])
1 [ 1 2 3 4 5 6 7 8 9 10 11 12] 2 [[ 1 2 3] 3 [ 4 5 6] 4 [ 7 8 9] 5 [10 11 12]] 6 [7 8 9] 7 6 8 [[ 1 2 3] 9 [ 4 5 6] 10 [ 7 8 9] 11 [10 11 12]] 12 [ 2 5 8 11] 13 [[ 1 2] 14 [ 4 5] 15 [ 7 8] 16 [10 11]] 17 [[123 ] 18 [789 ]] 19 [[12 ] 20 [78 ]] 21 is . 6 22 is . 6 23 is 67 24 . 6 25 [67 ] 26 the last row 27 [10 11 12 ] 28 descending line 29 [[10 11 12 ] 30 [789 ] 31 [456 ] 32 [123 ]] 33 [[121,110 ] 34 [987 ] 35 [654] 36 [ 3 2 1]]