How to check if a NumPy dtype is integral?

Learn, how to check if a NumPy dtype is integral?
Submitted by Pranit Sharma, on March 14, 2023

Checking whether a NumPy dtype is integral or not?

Data types are the category of values or types of values which can be used in programming for computations. To store different types of values (integer, decimal, characters, etc.) we need different data types in Python or any other programming language(s).

Numpy has a hierarchy of dtypes similar to a class hierarchy (the scalar types have a bona fide class hierarchy that mirrors the dtype hierarchy). We can use numpy.issubdtype(some_dtype, numpy.integer) to test if a dtype is an integer dtype.

Let us understand with the help of an example,

Python code to check if a NumPy dtype is integral

# Import numpy
import numpy as np

# Checking for different data types
print("check for int",np.issubdtype(np.int32, np.integer),"\n")
print("check for float",np.issubdtype(np.float32, np.integer),"\n")
print("check for complex",np.issubdtype(np.complex64, np.integer),"\n")

Output

Example: How to check if a NumPy dtype is integral?

Python NumPy Programs »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.