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)
Answer from Bruno Gelb on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.max.html
numpy.max — NumPy v2.2 Manual
>>> import numpy as np >>> a = np.arange(4).reshape((2,2)) >>> a array([[0, 1], [2, 3]]) >>> np.max(a) # Maximum of the flattened array 3 >>> np.max(a, axis=0) # Maxima along the first axis array([2, 3]) >>> np.max(a, axis=1) # Maxima along the second axis array([1, 3]) >>> np.max(a, where=[False, True], initial=-1, axis=0) array([-1, 3]) >>> b = np.arange(5, dtype=float) >>> b[2] = np.nan >>> np.max(b) np.float64(nan) >>> np.max(b, where=~np.isnan(b), initial=-1) 4.0 >>> np.nanmax(b) 4.0 ·
Discussions

np.max doesn't work for comparing float numbers
print (np.max(450.0802234473462, 85.0)) File "<__array_function__ internals>", line 6, in amax File "E:\miniconda3\envs\python37\lib\site-packages\numpy\core\fromnumeric.py", line 2621, in amax keepdims=keepdims, initial=initial, where=where) File "E:\miniconda3\envs\python37\lib\site-packages\numpy\core\fromnumeric.py", line 90, in _wrapreduction return ufunc.reduce(obj, axis, dtype, out, **passkwargs) TypeError: 'float... More on github.com
🌐 github.com
2
February 17, 2020
python - How to get the range of valid Numpy data types? - Stack Overflow
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? ... Save this answer. ... Show activity on this post. ... CopyIn [12]: finfo('d').max ... More on stackoverflow.com
🌐 stackoverflow.com
floating point - Python: Return max float instead of infs? - Stack Overflow
I have several functions with multiple calculations that might return inf, like so: In [10]: numpy.exp(5000) Out[10]: inf I'd rather it return the maximum float value: In [11]: sys.float_info.ma... More on stackoverflow.com
🌐 stackoverflow.com
python - Numpy 2d array with float values find the maximum value in a single row and store in another array - Stack Overflow
8 Find maximum of each row in a numpy array and the corresponding element in another array of the same size More on stackoverflow.com
🌐 stackoverflow.com
🌐
Note.nkmk.me
note.nkmk.me › home › python
Maximum and Minimum float Values in Python | note.nkmk.me
August 11, 2023 - However, in Python, the double-precision type is named float, and there's no dedicated single-precision type. Note that in NumPy, you can explicitly specify the type with the number of bits, such as float32 or float64.
🌐
GitHub
github.com › numpy › numpy › issues › 15586
np.max doesn't work for comparing float numbers · Issue #15586 · numpy/numpy
February 17, 2020 - Reproducing code example: import numpy as np print (np.max(450.0802234473462, 85.0)) Error message: print (np.max(450.0802234473462, 85.0)) File " ", line 6, in amax File "E:\miniconda3\envs\python37\lib\site...
Author: numpy
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.max.html
numpy.max — NumPy v2.5 Manual
>>> import numpy as np >>> a = np.arange(4).reshape((2,2)) >>> a array([[0, 1], [2, 3]]) >>> np.max(a) # Maximum of the flattened array 3 >>> np.max(a, axis=0) # Maxima along the first axis array([2, 3]) >>> np.max(a, axis=1) # Maxima along the second axis array([1, 3]) >>> np.max(a, where=[False, True], initial=-1, axis=0) array([-1, 3]) >>> b = np.arange(5, dtype=np.float64) >>> b[2] = np.nan >>> np.max(b) np.float64(nan) >>> np.max(b, where=~np.isnan(b), initial=-1) 4.0 >>> np.nanmax(b) 4.0 ·
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.finfo.html
numpy.finfo — NumPy v2.5 Manual
The number of bits in the exponent portion of the floating point representation. ... The exponent that yields eps. ... The largest representable number. ... The smallest positive power of the base (2) that causes overflow. Corresponds to the C standard MAX_EXP.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › article › get-the-machine-limits-information-for-float-types-in-python
Get the Machine limits information for float types in Python
February 24, 2022 - -65500.0 Maximum of float16 type... 65500.0 · Check the machine limits for 32-bit floating-point numbers ? import numpy as np # Get machine limits for float32 b = np.finfo(np.float32) print("Minimum of float32 type...") print(b.min) print("Maximum ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v2.5 Manual
Maximum value of given dtype. ... The equivalent for floating point data types.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › find maximum float value in python
Find Maximum Float Value in Python - Spark By {Examples}
May 31, 2024 - How to find the maximum float value in Python? You can find the maximum value of the float data type using the sys.float_info module or the finfo()
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.max.html
numpy.max — NumPy v2.0 Manual
>>> a = np.arange(4).reshape((2,2)) >>> a array([[0, 1], [2, 3]]) >>> np.max(a) # Maximum of the flattened array 3 >>> np.max(a, axis=0) # Maxima along the first axis array([2, 3]) >>> np.max(a, axis=1) # Maxima along the second axis array([1, 3]) >>> np.max(a, where=[False, True], initial=-1, axis=0) array([-1, 3]) >>> b = np.arange(5, dtype=float) >>> b[2] = np.nan >>> np.max(b) np.float64(nan) >>> np.max(b, where=~np.isnan(b), initial=-1) 4.0 >>> np.nanmax(b) 4.0 ·
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.max.html
numpy.max — NumPy v2.1 Manual
>>> import numpy as np >>> a = np.arange(4).reshape((2,2)) >>> a array([[0, 1], [2, 3]]) >>> np.max(a) # Maximum of the flattened array 3 >>> np.max(a, axis=0) # Maxima along the first axis array([2, 3]) >>> np.max(a, axis=1) # Maxima along the second axis array([1, 3]) >>> np.max(a, where=[False, True], initial=-1, axis=0) array([-1, 3]) >>> b = np.arange(5, dtype=float) >>> b[2] = np.nan >>> np.max(b) np.float64(nan) >>> np.max(b, where=~np.isnan(b), initial=-1) 4.0 >>> np.nanmax(b) 4.0 ·
🌐
Real Python
realpython.com › numpy-max-maximum
NumPy's max() and maximum(): Find Extreme Values in Arrays – Real Python
October 22, 2025 - But here, you just want to get the best view of the weekly maximum values. The solution, in this case, is another NumPy package function, np.fmax(): ... Now, two of the missing values have simply been ignored, and the remaining floating-point value at that index has been taken as the maximum.
🌐
SciPy
docs.scipy.org › doc › numpy-1.13.0 › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v1.13 Manual
The equivalent for floating point data types. ... >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647
🌐
University of Texas at Austin
het.as.utexas.edu › HET › Software › Numpy › reference › generated › numpy.finfo.html
numpy.finfo — NumPy v1.9 Manual
Machine limits for floating point types. ... The implementation of the tests that produce this information. ... The equivalent for integer data types. ... For developers of NumPy: do not instantiate this at the module level. The initial calculation of these parameters is expensive and negatively impacts import times.