
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Test Similar Int Types as Subtypes 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
Advertisements