我正在运行 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 类型。然后你想比较数据类型,而不是实际值。
>>> np.issubdtype(np.float, np.float)
True
你不能比较变量,只能比较类型。
关于python - Numpy issubdtype 给出 "TypeError: data type not understood",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53157460/