Datatype sizes

Integers

  • int8
  • int16
  • int32 (int for 32bits)
  • int64 (int for 64bits)
  • uint8
  • uint16
  • uint32
  • uint64
np.array([2**32], dtype=np.int32).dtype
# shows deprecation warning because of out-of-bound integer
# conversion to smaller data size

We can check the size of numpy integer datatype using method np.iinfo.

np.iinfo(np.int32)
# iinfo(min=-2147483648, max=2147483647, dtype=int32)

Floats

To check the size of float integers, we can use method np.finfo.

np.finfo(np.float64)
# finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64)

Available floats,

  • float16
  • float32
  • float64
  • float96 platform dependent (or np.longdouble)
  • float128 platform dependent (or np.longdouble)
np.finfo(np.float32).eps
# 1.1920929e-07

Note

eps is machine epsilon which defines round off error for float numbers.

Complex numbers

  • complex64 two bits floats
  • complex128 two bits floats
  • complex192 two bits floats, platform depedent
  • complex256 two bits floats, platform depedent

References

  1. https://lectures.scientific-python.org/intro/numpy/elaborate_arrays.html#different-data-type-sizes