Creating Numpy basis of the property

Import numpy AS NP 

'' ' 
to create an array of 1: np.array ([]) 
type 2 array object: type () 
3. Data Type: a.dtype 
type shape 4. arrays: (4,2, 3) 
bytes of each array element 5. define: array.itemsize 
'' ' 

# # Create a three-dimensional array 
a = [[1,2,1], [l, 3,4 ]] 
B = [[. 5 , 6,1], [1,7,8 ]] 
C = [[9,10,1], [11,12,1 ]] 
D = [[, 13, 14], [, 15, 16 ]] 

array_test = np.array ([A, B, C, D], DTYPE = ' float64 ' ) 

Print (array_test.shape)
 Print (array_test.ndim)
 Print (array_test.size)
 Print (array_test) 

'' '
(4, 2, 3) 
3 
24 
Explanation: 
Type Shape: (4, 2, 3)    
axes axes: the axis-dimensional array is called, the number of axes of three-dimensional array is referred to herein rank: shape three integer 
array length size: (total number of elements in the hierarchy) = 24 [3 * 2 * 4] 

homogeneity: a [4 wherein each element are the same type, such as a], [2 two elements of an element of a per are the same types, such as [1,2,1]], [3 three elements [1,2,3] an element of] 
Therefore, a Shape (4,2,3) 

'' ' 
Print (type (array_test))
 '' ' 
array class: <class' numpy.ndarray '> 
' '' 
Print (array_test.dtype)
 '' ' 
data type: Int32 
' '' 

Print (array_test.itemsize)   # #. 4 

# # Create the like difference array 
arange_array = np.arange (0,12) .reshape (3,4- ) 
linspace_array = np.linspace (0,10,5).reshape(5,1)
Print ( ' axes ' , arange_array.ndim)
 Print ( ' size: ' , linspace_array.size)
 Print (arange_array)
 Print (linspace_array)
 ' '' 
axes 2 
size:. 5 

[[2. 3. 1 0] 
 [. 4. 5. 6 7] 
 [8 9 10 11]] 
[[0.5] 
 [2.5] 
 [5] 
 [7.5] 
 [10]] 
'' ' 

# # Create a random number sequence 
# D random number sequence 
rand_1d = np.random.random ( . 4 )
 Print (rand_1d)
 '' ' 
[0.08525778 0.12143347 .56587575 .83590871] 
' ''
#The one dimensional into 2D 
Print (rand_1d.reshape (2,2 & ))
 '' ' 
[[0.08525778 0.12143347] 
 [.56587575 0.83590871]] 
' '' 

# # passed directly generate multidimensional array shape can 

Print (np.random .random ((3,3 )))
 '' ' 
[[0.56859463 0.98880884 .52755145] 
 [0.26863131 0.71508455 .22285108] 
 [0.31286731 0.2290022 0.7223287]] 
' ''

 

Guess you like

Origin www.cnblogs.com/liuhuacai/p/11578650.html