I'm interested in finding for a particular Numpy type (e.g. np.int64
, np.uint32
, np.float32
, etc.) what the range of all possible valid values is (e.g. np.int32
can store numbers up to 2**31-1
). Of course, I guess one can theoretically figure this out for each type, but is there a way to do this at run time to ensure more portable code?
The astype() function creates a copy of the array, and allows you to specify the data type as a parameter. The data type can be specified using a string, like 'f' for float, 'i' for integer etc. or you can use the data type directly like float for float and int for integer.
That is, the value range [0,255*256] is mapped to [0,255].
There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex.
Quoting from a numpy discussion list:
That information is available via
numpy.finfo()
andnumpy.iinfo()
:In [12]: finfo('d').max Out[12]: 1.7976931348623157e+308 In [13]: iinfo('i').max Out[13]: 2147483647 In [14]: iinfo('uint8').max Out[14]: 255
Link here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With