[Numpy-discussion] get a dtypes' range?

Bruce Southey bsouthey@gmail....
Fri Jun 17 14:02:40 CDT 2011


On 06/17/2011 12:38 PM, Christopher Barker wrote:
> Hi all,
>
> I'm wondering if there is a way to get the range of values a given dtype
> can hold?
>
> essentially, I'm looking for something like sys.maxint, for for whatever
> numpy dtype I have n hand (and eps for floating point types).
>
> I was hoping there would be something like
>
> a_dtype.max_value
> a_dtype.min_value
>
> etc.
>
> In this case, I have a uint16, so I can hard code it, but it would be
> nice to be able to be write the code in a more generic fashion.
>
> -Chris
>

Do you mean np.finfo() and np.iinfo()?

 >>> print np.finfo(float)
Machine parameters for float64
---------------------------------------------------------------------
precision= 15   resolution= 1.0000000000000001e-15
machep=   -52   eps=        2.2204460492503131e-16
negep =   -53   epsneg=     1.1102230246251565e-16
minexp= -1022   tiny=       2.2250738585072014e-308
maxexp=  1024   max=        1.7976931348623157e+308
nexp  =    11   min=        -max
---------------------------------------------------------------------

 >>> print np.iinfo(int)
Machine parameters for int64
---------------------------------------------------------------------
min = -9223372036854775808
max = 9223372036854775807
---------------------------------------------------------------------
 >>> sys.maxint
9223372036854775807


Bruce



More information about the NumPy-Discussion mailing list