1 Import NumPy as NP
Dimension transformations
1 a = Np.arange (2 a)
Array ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ten, one, one,,
17, 18, 19, 20, 21, 22, 23])
Reshape (), view, do not modify the original array
1 a.reshape (4,6)
Array ([[0, 1, 2, 3, 4, 5], 6, 7, 8, 9, ten, one], [12 , +, +, 18, 19, 20 , 21, 22, 23])
1 a.reshape (2,3,4)
Array ([[[[0, 1, 2, 3] ,4, 5, 6, 7] ,8, 9, 10, [20, 21, 22, 23]], [ [[+]], [[+], []
1 A
Array ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ten, one,a,, 17, 18, 19, 20, 21, 22, 23])
Resize () modifying the original array
1 a.resize (2,3,4)
1 A
Array ([[[0, 1, 2, 3], 4, 5, 6, 7], 8, 9, ten, one]] , [ [20, 21, 22, 23]], [[+], [[ ] ]
Descending dimension of array, returning the collapsed one-dimensional array, modifying the view
1 a.flatten ()
Array ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ten, one,a,, 17, 18, 19, 20, 21, 22, 23])
Type transformation
1 B = Np.array ([true,20,177.7])2 b,b.dtype
(Array ([ 1., 177.7]), Dtype ('float64'))
1 # modifying types when defining arrays 2 Np.array ([True,20,177.7],dtype=np.int)
Array ([ 1, 20, 177])
1 # Modify type when calling array #并不改变原数组 2b3# Change View
Array ([ 1, 20, 177])
1 b.astype (np.unicode_)
Array (['1.0'20.0'177.7'), Dtype='<u32')
1 b
Array ([ 1., 20., 177.7])
Ndarray Array Transformations