[英]Numpy issubdtype gives “TypeError: data type not understood”
I'm running python 2.7 and numpy 1.15. 我正在运行python 2.7和numpy 1.15。
I get: 我得到:
>>> 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
Did something change so that it used to work with values, but now it only works with types? 发生了什么变化,以便它过去可以与值一起使用,但是现在仅与类型一起使用?
As per an answer below: 按照下面的答案:
>>> 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
I should add that 我应该补充一点
>>> np.issubdtype(type(4), np.float)
False
works... but the code USED to work without type()
... 可以...但是代码不用type()
...
Use the numpy types first. 首先使用numpy类型。 Then you want to compare dtypes, not actual values. 然后,您要比较dtype,而不是实际值。
>>> np.issubdtype(np.float, np.float)
True
You cannot compare variables, only types. 您不能比较变量,只能比较类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.