Test whether float datatype of different sizes are not subdtypes of each other in Python


To check whether float data types of different sizes are not subdtypes of each other, 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 float datatype with different sizes −

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

Example

import numpy as np

# To check whether float data types of different sizes are not subdtypes of each other, 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 float datatype with different sizes
print("Result...",np.issubdtype(np.float16, np.float32))
print("Result...",np.issubdtype(np.float32, np.float16))
print("Result...",np.issubdtype(np.float64, np.float32))
print("Result...",np.issubdtype(np.float32, np.float64))
print("Result...",np.issubdtype(np.float16, np.float64))
print("Result...",np.issubdtype(np.float64, np.float16))

Output

Using the issubdtype() method in Numpy

Result... False
Result... False
Result... False
Result... False
Result... False
Result... False

Updated on: 24-Feb-2022

49 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements