python - Numpy issubdtype 给出 "TypeError: data type not understood"

标签 python python-2.7 numpy

我正在运行 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/

相关文章:

python - 高效地获取列特定列表比较中的唯一条目

python - 无法从 python 3 中的输入文件中找到子字符串

python - f2py: 找不到可执行文件 C:Python27pythonw.exe 可执行文件 C:Python27pythonw.exe 不存在

python - 在 numpy 中计算 L2 内积?

python - celery 不应该以 root 身份运行的原因是什么?

python - 如何为numpy数组创建圆形蒙版?

python - 如何删除复选框小部件 tkinter 周围的浅灰色?

javascript - Django 的 CSRF 验证失败,尽管 Firebug 说 cookies 选项卡下有一个 csrftoken。为什么?

python - Emacs 24.3 python : Can't guess python-indent-offset, 使用默认值 4

python - 有没有更快的方法来获得相关系数?