在 Python 中测试不同大小的类似浮点类型是否是浮点数类的子类型
要测试不同大小的类似浮点类型是否是浮点数类的子类型,请在 Python Numpy 中使用 numpy.issubdtype() 方法。参数可以强制转换为 dtype 或对象。
步骤
首先,导入必需的库 −
import numpy as np
在 Numpy 中使用 issubdtype() 方法。检查具有不同大小的浮点数数据类型 −
print("Result...",np.issubdtype(np.float16, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype(np.float64, np.floating))示例
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))输出
Using the issubdtype() method in Numpy Result... True Result... True Result... True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP