Maximum allowed value for a numpy data type

Learn about the maximum allowed value for a numpy data type in Python.
Submitted by Pranit Sharma, on January 11, 2023

NumPy is an abbreviated form of Numerical Python. It is used for different types of scientific operations in python. Numpy is a vast library in python which is used for almost every kind of scientific or mathematical operation. It is itself an array which is a collection of various methods and functions for processing the arrays.

NumPy's datatype - Maximum allowed value

We are given some NumPy arrays of a range of data types (uint8, uint16, int16, etc.). we need to check whether a number can be represented within the limits of an array for a given datatype.

Numpy provides us a method numpy.iinfo() which takes im.dtype argument and it contains some attributes like min or max which tells us about the maximum allowed value for a NumPy data type.

Let us understand with the help of an example,

Python code to demonstrate the maximum allowed value for a numpy data type

# 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")

Output:

Example: Maximum allowed value for a numpy data type

Python NumPy Programs »



ADVERTISEMENT
ADVERTISEMENT


What's New (MCQs)



Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.