Maximum allowed value for a numpy data type

Learn about the maximum allowed value for a numpy data type in Python. By Pranit Sharma Last updated : October 09, 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 program 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

The output of the above program is:

Example: Maximum allowed value for a numpy data type

Python NumPy Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.