Created: Np.array ()
A = Np.array ([1,2,3,4= Np.array ([1,2,3, 4] [4,5,6,7] [7,8,9,ten])
a[1,2,3,4]b[[1,2,3,4 ],[4,5,6,7],[7,8, 9, [ten]]
Get: Tuple of the length of each axis of an array shape . Shape ()
>>a.shape (4,)>>b.shape (3,4)
Modify the length of the axis (memory address unchanged):. Shape =
4,3>>barray ([[1,2,3], [4, 4,5], [6,7,7], [8 ,9,ten]])
>>b.shape =2,-1 % set an axis of 1 to automatically calculate the length
>>b
Array ([[[1,2,3,4,4,5],
[6,7,7,8,9,10]])
Create another array of shapes with existing array data: = . Reshape ()
(both share data at this point, i.e. the data address is the same)
>>c = A.reshape (2,2) %reshape ((2,2)) can also >>CArray ([[1,2], [3,4]])
Element type: . Dtype
Array created with an integer subscript, default 32-bit long integer (32-bit Python)
>>c.dtype
Dtype (' int32 ')
Create an array and specify the parameters
>>AI32 = Np.array ([1,2,3,4],dtype=np.int32)>>af = Np.array ([1,2,3,4],dtype=float)>>ac = Np.array ([ 1,2,3,4],dtype=complex)
>>a = np.int16 (200)
>>a*a
-25536 %int16 Not enough, calculate 200*200 overflow
accessing arrays
>>a = Np.array () Array ([012345 6 7 8 9 ])>>a[5] % use integer as subscript to get an element in an array
>>a[3:5]% do subscript with slices, get part of the array, including a[3] not including a[5]
>>a[:5] % starting from 0 to A[4], excluding a[5]
>>A[:-1]% The following table uses a negative number, which means starting from 0 until the last 1 of the array is not included
a[5]5a[3:5][3 4]a[:5][0 1 2 3 4]a[:-1][0 1 2 3 4 5 6 7 8]
Python--numpy Study Notes