[Numpy-discussion] get range of numpy type

Nathan Bell wnbell@gmail....
Wed Jun 4 01:17:08 CDT 2008


On Wed, Jun 4, 2008 at 12:16 AM, Christopher Burns <cburns@berkeley.edu> wrote:
> Is there a way to get the range of a numpy type?  I'd like to clamp a
> parameter to be within the range of a numpy type, np.uint8, np.uint32...
>
> Something like:
> if x > max_value_of(np.uint8):
>    x = max_value_of(np.uint8)

That kind of 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


-- 
Nathan Bell wnbell@gmail.com
http://graphics.cs.uiuc.edu/~wnbell/


More information about the Numpy-discussion mailing list