from numpy import * import numpy as np # numpy Simple application examples print(eye(4)) # Create simple ndarray object a = np.array([1, 2, 3]) print(a) # Create greater than 1 An array of dimensions Use ndmin Parameters ,ndmin The default value of the parameter is 0 b = np.array([1, 2, 3], ndmin=2) print(b) b1 = np.array([2, 3, 4],ndmin=-1) print(b1) # Create an array of composite types c = np.array([1, 2, 3],dtype=complex) print(c) # see dtype Use examples # Create an array , View the data type of the array da = np.array([1, 2, 3]) print(da.dtype) # Create a dt = np.dtype('i4') print(dt) # The use of structured data types # First create structured data types da = np.dtype(np.int64) print(da) dt = np.dtype([('age',np.int8)]) print(dt) # Apply structured data types to ndarray object dt = np.dtype([('age',np.int8)]) a = np.array([(10,),(20,),(30,)], dtype = dt) print(a) # Use the type object to access the actual column dt = np.dtype([('age',np.int8)]) a = np.array([(10,),(20,),(30,)], dtype = dt) print(a['age']) # Define a structured data type student, Contains string fields name, Integer fields age, And floating point fields marks, And will the dtype Applied to the ndarray object # Create array student = np.dtype([('name','S20'), ('age', 'i1'), ('marks', 'f4')]) # Use array for ndarray object a = np.array([('abc', 21, 50),('xyz', 18, 75)], dtype = student) print(a) # NumPy Data type conversion instance da = np.array([1.2,1.1,1.0]) # Output da Data type of print(da.dtype) # transformation da Data type of print(da.astype(np.int32)) # Revisit the data type , Found that the data type has not changed print(da.dtype) # Re assign the value da = da.astype(np.int32) print(da.dtype) print(da)