Get the Machine limits information for int with instances in Python


To get the machine limits information for integer types, use the numpy.iinfo() method in Python Numpy. The first parameter is the int_type i.e. the kind of integer data type to get information about.

Steps

At first, import the required library −

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 with instances −

b = np.iinfo(np.int32(30))
print("\nMinimum of int32 type...\n",b.min)
print("Maximum of int32 type...\n",b.max)

Checking for int64 type with instances −

c = np.iinfo(np.int64(50))
print("\nMinimum of int64 type...\n",c.min)
print("Maximum of int64 type...\n",c.max)

Example

import numpy as np

# To get the machine limits information for integer types, use the numpy.iinfo() method in Python Numpy
# The first parameter is the int_type i.e. the kind of integer data type to get information about.

# Checking for int16 type with instances
# The min is the minimum value of given dtype.
# The max is the minimum value of given dtype.
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 with instances
b = np.iinfo(np.int32(30))
print("\nMinimum of int32 type...\n",b.min)
print("Maximum of int32 type...\n",b.max)

# Checking for int64 type with instances
c = np.iinfo(np.int64(50))
print("\nMinimum of int64 type...\n",c.min)
print("Maximum of int64 type...\n",c.max)

Output

Minimum of int16 type...
-32768
Maximum of int16 type...
32767

Minimum of int32 type...
-2147483648
Maximum of int32 type...
2147483647

Minimum of int64 type...
-9223372036854775808
Maximum of int64 type...
9223372036854775807

Updated on: 24-Feb-2022

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements