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 › stable › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v2.3 Manual
>>> import numpy as np >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v2.2 Manual
>>> import numpy as np >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647
🌐
TutorialsPoint
tutorialspoint.com › article › get-the-machine-limits-information-for-integer-types-in-python
Get the Machine limits information for integer types in Python
... The min is the minimum value of given dtype and max is the minimum value of given dtype. ... a = np.iinfo(np.int16) print("Minimum of int16 type...\n",a.min) print("Maximum of int16 type...\n",a.max)
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.5.dev0 Manual
>>> np.iinfo(int) # Bounds of the default integer on this system. iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64) >>> np.iinfo(np.int32) # Bounds of a 32-bit integer iinfo(min=-2147483648, max=2147483647, dtype=int32) >>> np.iinfo(np.int64) # Bounds of a 64-bit integer ...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v2.5.dev0 Manual
See also · finfo · The equivalent for floating point data types. Examples · Try it in your browser! With types: >>> import numpy as np >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647 ·
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How to check minimum and maximum values of NumPy data type? - Python - Data Science Dojo Discussions
March 1, 2023 - I have learned that all datatypes of the NumPy library have their minimum and maximum values. Understanding the minimum and maximum values of a NumPy data type is useful because it can help prevent overflow or underflow …
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.01-understanding-data-types.html
Understanding Data Types in Python | Python Data Science Handbook
The standard NumPy data types are listed in the following table. Note that when constructing an array, they can be specified using a string: np.zeros(10, dtype='int16') Or using the associated NumPy object: np.zeros(10, dtype=np.int16) More advanced type specification is possible, such as specifying big or little endian numbers; for more information, refer to the NumPy documentation.
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
>>> np.iinfo(int) # Bounds of the default integer on this system. iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64) >>> np.iinfo(np.int32) # Bounds of a 32-bit integer iinfo(min=-2147483648, max=2147483647, dtype=int32) >>> np.iinfo(np.int64) # Bounds of a 64-bit integer ...
Find elsewhere
🌐
IncludeHelp
includehelp.com › python › maximum-allowed-value-for-a-numpy-data-type.aspx
Python - Maximum allowed value for a numpy data type
October 9, 2023 - # Import numpy import numpy as np # Maximum allowed value max = np.iinfo(np.int16).max # Minimum allowed value min = np.iinfo(np.int16).min # Display result print("Max:\n",max,"\n") print("Min:\n",min,"\n")
🌐
NumPy
numpy.org › doc › 1.20 › user › basics.types.html
Data types — NumPy v1.20 Manual
January 31, 2021 - >>> np.iinfo(int) # Bounds of the default integer on this system. iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64) >>> np.iinfo(np.int32) # Bounds of a 32-bit integer iinfo(min=-2147483648, max=2147483647, dtype=int32) >>> np.iinfo(np.int64) # Bounds of a 64-bit integer ...
🌐
University of Texas at Austin
het.as.utexas.edu › HET › Software › Numpy › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v1.9 Manual
class numpy.iinfo(type)[source]¶ · Machine limits for integer types. See also · finfo · The equivalent for floating point data types. Examples · With types: >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max ...
🌐
w3resource
w3resource.com › numpy › data-type-routines › iinfo.php
NumPy Data type: iinfo() function - w3resource
August 19, 2022 - >>> import numpy as np >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647 · Example: numpy.iinfo() function · >>> import numpy as np >>> ii32 ...
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v2.1 Manual
>>> import numpy as np >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max 2147483647
🌐
Hyperskill
hyperskill.org › learn › step › 10095
Data types in NumPy
Hyperskill is an educational platform for learning programming and software development through project-based courses, that helps you secure a job in tech. Master Python, Java, Kotlin, and more with real-world coding challenges.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.max.html
numpy.max — NumPy v2.2 Manual
Return the maximum of an array or maximum along an axis · Axis or axes along which to operate. By default, flattened input is used. If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.types.html
Data types — NumPy v1.22 Manual
>>> np.iinfo(int) # Bounds of the default integer on this system. iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64) >>> np.iinfo(np.int32) # Bounds of a 32-bit integer iinfo(min=-2147483648, max=2147483647, dtype=int32) >>> np.iinfo(np.int64) # Bounds of a 64-bit integer ...
🌐
TutorialsPoint
tutorialspoint.com › get-the-machine-limits-information-for-int-with-instances-in-python
Get the Machine limits information for int with instances in Python
February 24, 2022 - import numpy as np · The min is the minimum value of given dtype and max is the minimum value of given dtype. Checking for int16 type with instances − · a = np.iinfo(np.int16(20)) print("Minimum of int16 type...\n",a.min) print("Maximum of int16 type...\n",a.max) Checking for int32 type ...
🌐
SciPy
docs.scipy.org › doc › numpy-1.13.0 › reference › generated › numpy.iinfo.html
numpy.iinfo — NumPy v1.13 Manual
class numpy.iinfo(type)[source]¶ · Machine limits for integer types. See also · finfo · The equivalent for floating point data types. Examples · With types: >>> ii16 = np.iinfo(np.int16) >>> ii16.min -32768 >>> ii16.max 32767 >>> ii32 = np.iinfo(np.int32) >>> ii32.min -2147483648 >>> ii32.max ...
🌐
NumPy
numpy.org › doc › 1.18 › user › basics.types.html
Data types — NumPy v1.18 Manual
>>> np.iinfo(int) # Bounds of the default integer on this system. iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64) >>> np.iinfo(np.int32) # Bounds of a 32-bit integer iinfo(min=-2147483648, max=2147483647, dtype=int32) >>> np.iinfo(np.int64) # Bounds of a 64-bit integer ...