Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the range of valid Numpy data types?

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?

like image 378
astrofrog Avatar asked Nov 01 '09 23:11

astrofrog


People also ask

How can you identify the datatype of a given NumPy array?

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.

What is the range of unit 8 data type in NumPy?

That is, the value range [0,255*256] is mapped to [0,255].

How many data types are there in a NumPy array?

There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex.


1 Answers

Quoting from a numpy discussion list:

That information is available via numpy.finfo() and numpy.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.

like image 191
perimosocordiae Avatar answered Oct 11 '22 19:10

perimosocordiae