Test whether similar int type of different sizes are subdtypes of integer class in Python


To test whether similar int type of different sizes are subdtypes of integer class, use the numpy.issubdtype() method in Python Numpy. The parameters are the dtype or object coercible to one.

Steps

At first, import the required library −

import numpy as np

Using the issubdtype() method in Numpy. Checking for integer datatype with different sizes −

print("Result...",np.issubdtype(np.int16, np.signedinteger))
print("Result...",np.issubdtype(np.int32, np.signedinteger))
print("Result...",np.issubdtype(np.int64, np.signedinteger))
print("Result...",np.issubdtype(np.int16, np.integer))
print("Result...",np.issubdtype(np.int32, np.integer))
print("Result...",np.issubdtype(np.int64, np.integer))

Example

import numpy as np

# To test whether similar int type of different sizes are subdtypes of integer class, use the numpy.issubdtype() method in Python Numpy.
# The parameters are the dtype or object coercible to one
print("Using the issubdtype() method in Numpy\n")

# Checking for integer datatype with different sizes
print("Result...",np.issubdtype(np.int16, np.signedinteger))
print("Result...",np.issubdtype(np.int32, np.signedinteger))
print("Result...",np.issubdtype(np.int64, np.signedinteger))
print("Result...",np.issubdtype(np.int16, np.integer))
print("Result...",np.issubdtype(np.int32, np.integer))
print("Result...",np.issubdtype(np.int64, np.integer))

Output

Using the issubdtype() method in Numpy

Result... True
Result... True
Result... True
Result... True
Result... True
Result... True

Updated on: 24-Feb-2022

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements