First module into file
import numpy as np
1, when creating an array of the specified type
arr = np.arange(0, 6, 1, dtype=np.int64)
arr = np.arange(0, 6, 1, dtype=np.float64)
Use aRange () creates an array method, parameter dtype setting data in the array type element using aRange () array element can not be created by a method as specified bool type
2, create the element type of an array of bool
arr = np.array([0, 1, 2, 3, 4], dtype=np.bool)
Use aRange () creates an array method, the element can specify the data type bool type
3, the forced conversions between data types
np.bool (1 )
np.float64 (0)
np.str (0)
np.int32 (0)
Use bool (), float64 (), str (), int32 () method on the data type of the array mandatory conversion parameter is an array to be transformed
4, after the array is created, go to modify the data type of the array
arr.dtype = np.int32
arr = arr.astype(np.int32)
Use dtype property or asType () method to modify the data type array
5, custom data types
df = np.dtype([("name", np.str, 40), ("hight", np.float64), ("weight", np.float64)]) arr = np.array([("bq", 168.5, 55.0), ("nl", 178.5, 65.0), ("yf", 175, 60)], dtype=df)
Use type () method of custom data types