- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine if the type in the first argument is a subclass of second in Python
To determine if the type in the first argument is a subclass of second, use the numpy.issubsctype() method in Python numpy. The 1st and the 2nd argument are datatypes.
Steps
At first, import the required library −
import numpy as np
Using the issubsctype() method in Numpy. Checking whether the first argument is a subclass of the second argument −
print("Result...",np.issubsctype(np.float16, np.float32)) print("Result...",np.issubsctype(np.int32, np.signedinteger)) print("Result...",np.issubsctype('i4', np.signedinteger)) print("Result...",np.issubsctype('S8', str)) print("Result...",np.issubsctype(np.array([45, 89]), int)) print("Result...",np.issubsctype(np.array([5., 25., 40.]), float))
Example
import numpy as np # To determine if the type in the first argument is a subclass of second, use the numpy.issubsctype() method in Python numpy # The 1st and the 2nd argument are datatypes print("Using the issubsctype() method in Numpy\n") # Checking whether the first argument is a subclass of the second argument print("Result...",np.issubsctype(np.float16, np.float32)) print("Result...",np.issubsctype(np.int32, np.signedinteger)) print("Result...",np.issubsctype('i4', np.signedinteger)) print("Result...",np.issubsctype('S8', str)) print("Result...",np.issubsctype(np.array([45, 89]), int)) print("Result...",np.issubsctype(np.array([5., 25., 40.]), float))
Output
Using the issubsctype() method in Numpy Result... False Result... True Result... True Result... False Result... True Result... True
Advertisements