繁体   English   中英

Numpy issubdtype给出“ TypeError:数据类型无法理解”

[英]Numpy issubdtype gives “TypeError: data type not understood”

我正在运行python 2.7和numpy 1.15。

我得到:

>>> import numpy as np
>>> np.issubdtype(4, float)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brianp/work/cyan/venv/lib/python2.7/site-packages/numpy/core/numerictypes.py", line 714, in issubdtype
    arg1 = dtype(arg1).type
TypeError: data type not understood

发生了什么变化,以便它过去可以与值一起使用,但是现在仅与类型一起使用?

按照下面的答案:

>>> np.issubdtype(4, np.float)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brianp/work/cyan/venv/lib/python2.7/site-packages/numpy/core/numerictypes.py", line 714, in issubdtype
    arg1 = dtype(arg1).type
TypeError: data type not understood

我应该补充一点

>>> np.issubdtype(type(4), np.float)
False

可以...但是代码不用type() ...

首先使用numpy类型。 然后,您要比较dtype,而不是实际值。

>>> np.issubdtype(np.float, np.float)
True

您不能比较变量,只能比较类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM