Test whether similar float type of different sizes are subdtypes of floating class in Python


To test whether similar float type of different sizes are subdtypes of floating 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 floating point datatype with different sizes −

print("Result...",np.issubdtype(np.float16, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype(np.float64, np.floating))

Example

import numpy as np

# To test whether similar float type of different sizes are subdtypes of floating 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 floating point datatype with different sizes
print("Result...",np.issubdtype(np.float16, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype(np.float64, np.floating))

Output

Using the issubdtype() method in Numpy

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

Updated on: 25-Feb-2022

51 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements