测试不同大小的浮点数数据类型在 Python 中不是相互的子类型
要检查不同大小的浮点数数据类型是否是相互的子类型,请在 Python Numpy 中使用 numpy.issubdtype() 方法。参数是可转换为对象的数据类型。
步骤
首先,导入所需的库 −
import numpy as np
在 Numpy 中使用 issubdtype() 方法。检查具有不同大小的浮点数数据类型 −
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))
示例
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))
输出
Using the issubdtype() method in Numpy Result... False Result... False Result... False Result... False Result... False Result... False
广告