Python np.float不匹配np.float32和np.float64

Python np.float不匹配np.float32和np.float64,python,numpy,stumpy,Python,Numpy,Stumpy,我正在寻找一种方法来检查numpy数组是np.float64还是np.float32。这适用于np.float64: a = np.random.rand(10) if not issubclass(a.dtype.type, np.float): raise "Wrong type" # No exception is raised for np.float64 但是对于np.float32,失败: a = np.random.rand(10).astype(np.float32

我正在寻找一种方法来检查numpy数组是
np.float64
还是
np.float32
。这适用于
np.float64

a = np.random.rand(10)

if not issubclass(a.dtype.type, np.float):
    raise "Wrong type"  # No exception is raised for np.float64
但是对于
np.float32
,失败:

a = np.random.rand(10).astype(np.float32)

if not issubclass(a.dtype.type, np.float):
    raise "Wrong type"  # An exception is raised!

检查数据类型是否为浮动的一种方法是使用
issubdtype

In [1]: a = np.random.rand(10).astype(np.float64)

In [2]: b = np.random.rand(10).astype(np.float32)

In [3]: np.issubdtype(a.dtype,np.floating)
Out[3]: True

In [4]: np.issubdtype(b.dtype,np.floating)
Out[4]: True

a.dtype.type in(np.float32,np.float64)
行吗?是的,它行得通,这正是我们计划做的,但似乎奇怪的是
np.float32
np.float64
都不是
np.float
的子类。如果不是issubclass(a.dtype.type,(np.float32,np.float64,np.float)),我们将使用
但这似乎很详细,在64位系统上,系统类型
float
是64位的,因此numpy不将32位float视为子类型是有道理的。我得到:FutureWarning:将issubdtype的第二个参数从
float
转换为
np。不推荐使用floating
。将来,它将被视为
np.float64==np.dtype(float).type
。在numpy版本
1.13.3
中不会向我发出警告。您使用的是什么版本?我还使用版本
1.17.0
进行了测试,它在没有警告的情况下工作。您确定使用了
np.float
而不是
np.float