Data types in NumPy
NumPy supports a wide variety of data types. It is given using an attribute dtype which is a short form of data type. Most of the array creator/initializer function needs this arguments. Althoug optional, it helps numpy to determine the type of data type that array will store.
Use of dtype NumPy
Some time it is beneficial to use smaller data type to save memory and improve performance of NumPy code. On the other hand, use of higher precision data type e.g. use of double instead of float can reduce propagation truncation or round-off errors like in CFD.
Following table list the all the data types in Numpy (dtype Numpy) along with its ranges.
|NumPy type||C type||Description|
|np.int8||8 bit signed Integer with range = -128 to 127|
|np.int16||16 bit signed Integer with range = -32,768 to 32,767|
|np.int32||32 bit signed Integer with range = -2.147483648E+9 to 2.147483647E+9|
|np.int64||64 bit signed Integer with range = -9.223372036854775808E+18 to 9.223372036854775807E+18|
|np.uint8||8 bit unsigned Integer with range = 0 to 255|
|np.uint16||16 bit unsigned Integer with range = 0 to 65,535|
|np.uint32||32 bit unsigned Integer with range = 0 to 4.294967295E+9|
|np.uint64||64 bit unsigned Integer with range = 0 to 1.8446744073709551615E+19|
|np.intp||Integer used for indexing, typically the same as |
|np.uintp||Integer large enough to hold a pointer|
|np.float32||32 bit floating point number with range = -3.4E+38 to +3.4E+38|
|np.float64 / np.float_||64 bit floating point number or double precision float popularly known as double with range = -1.7E+308 to +1.7E+308|
|np.complex64||Complex number, represented by two 32-bit floats (real and imaginary components)|
|np.complex128 / np.complex_||Complex number, represented by two 64-bit floats (real and imaginary components).|
Note that this matches the precision of the builtin python complex.