min_value = np.iinfo(im.dtype).min
max_value = np.iinfo(im.dtype).max
docs:
np.iinfo(machine limits for integer types)np.finfo(machine limits for floating point types)
min_value = np.iinfo(im.dtype).min
max_value = np.iinfo(im.dtype).max
docs:
np.iinfo(machine limits for integer types)np.finfo(machine limits for floating point types)
You're looking for numpy.iinfo for integer types. Documentation here.
There's also numpy.finfo for floating point types. Documentation here.
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.
You can use numpy.iinfo(arg).max to find the max value for integer types of arg, and numpy.finfo(arg).max to find the max value for float types of arg.
>>> numpy.iinfo(numpy.uint64).min
0
>>> numpy.iinfo(numpy.uint64).max
18446744073709551615L
>>> numpy.finfo(numpy.float64).max
1.7976931348623157e+308
>>> numpy.finfo(numpy.float64).min
-1.7976931348623157e+308
iinfo only offers min and max, but finfo also offers useful values such as eps (the smallest number > 0 representable) and resolution (the approximate decimal number resolution of the type of arg).
You can use a decorator:
import sys
def noInf(f):
def wrapped(*args, **kwargs):
res = f(*args, **kwargs)
if res == float('inf'):
return sys.float_info.max
return res
return wrapped
@noInf
def myMult(x, y):
return x*y
print(myMult(sys.float_info.max, 2)) # prints 1.79769313486e+308
I don't know about 'replacing' infinity value, but what about using min()?
Something like (assuming x yields your value):
return min ( [ x, sys.float_info.max ] )