Skip to content

Dtype NumPy: List of Data Types in NumPy and its Ranges

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 typeC typeDescription
np.int8<span class="pre">int8_t</span>8 bit signed Integer with range = -128 to 127
np.int16<span class="pre">int16_t</span>16 bit signed Integer with range = -32,768 to 32,767
np.int32<span class="pre">int32_t</span>32 bit signed Integer with range = -2.147483648E+9 to 2.147483647E+9
np.int64<span class="pre">int64_t</span>64 bit signed Integer with range = -9.223372036854775808E+18 to 9.223372036854775807E+18
np.uint8<span class="pre">uint8_t</span>8 bit unsigned Integer with range = 0 to 255
np.uint16<span class="pre">uint16_t</span>16 bit unsigned Integer with range = 0 to 65,535
np.uint32<span class="pre">uint32_t</span>32 bit unsigned Integer with range = 0 to 4.294967295E+9
np.uint64<span class="pre">uint64_t</span>64 bit unsigned Integer with range = 0 to 1.8446744073709551615E+19
np.intp<span class="pre">intptr_t</span>Integer used for indexing, typically the same as <span class="pre">ssize_t</span>
np.uintp<span class="pre">uintptr_t</span>Integer large enough to hold a pointer
np.float32<span class="pre">float</span>32 bit floating point number with range = -3.4E+38 to +3.4E+38
np.float64 / np.float_<span class="pre">double</span>64 bit floating point number or double precision float popularly known as double with range = -1.7E+308 to +1.7E+308
np.complex64<span class="pre">float</span> <span class="pre">complex</span>Complex number, represented by two 32-bit floats (real and imaginary components)
np.complex128 / np.complex_<span class="pre">double</span> <span class="pre">complex</span>Complex number, represented by two 64-bit floats (real and imaginary components).

Note that this matches the precision of the builtin python complex.

 

Leave a Reply

Your email address will not be published. Required fields are marked *