python - 模块 'scipy.special' 在 Python/SciPy 中没有 'expit' 成员

标签 python python-3.x numpy scipy

我尝试使用 SciPy 中的 expit(x)。但我收到此错误消息:

Module 'scipy.special' has no 'expit' member

这是我的代码:

import numpy
import scipy.special

[...]

def Activation(self, ActivationInput):
    self.ActivationOutput = scipy.special.expit(ActivationInput)
    return self.ActivationOutput
当我尝试在函数 Activation 中使用

scipy 时,它在 VScode 中带有红色下划线

解决方案通过Error importing scipy.special.expit不令人满意并且不起作用。

我使用 Python 3.7、NumPy 1.14.5 和 SciPy 1.1.0。

其他函数可以工作,但来自 scipy.special 的所有 Ufunc 都会收到此错误消息。

最佳答案

scipy.special 中的所有 ufunc 都是用 C 编写的,因此 pylint 无法找到正确的定义。您可以通过向 pylint 添加选项 --ignored-modules=scipy.special 来告诉 pylint 忽略该模块。

对于 VSCode:

可以通过选项 GUI 或直接添加 --ignored-modules=scipy.special 到 settings.JSON 文件,但它会关闭 VSCode 与 pylint 一起使用的默认选项。

要解决此问题,您可以将原始默认选项以及 --ignored-modules 标志添加到 settings.json 文件中。

  • 输入[CTRL]+[Shift]+p 打开命令搜索
  • 搜索打开设置 (JSON),这将打开您的设置文件。
  • settings.JSON 中添加键/值对,以便您的文件具有以下内容
{
    // any other options for VSCode

    "python.linting.pylintArgs": [
        "--disable=all",
        "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned",
        "--enable=unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",
        "--ignored-modules=scipy.special"
        ],
}

前 3 行是 VSCode 用于 pylint 的默认选项。第 4 行告诉 pylint 忽略 scipy.special 模块,这将关闭错误。

关于python - 模块 'scipy.special' 在 Python/SciPy 中没有 'expit' 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51487479/

相关文章:

python - 乘以 Numpy 矩阵的列时出现问题

python - 在 Python 中从列表中删除元素

python - Pandas concat DataFrames - 保持索引的原始顺序

python - 更改 CSV 列中的数据格式

Python:设置 Numpy 矩阵的元素

python - 停止动画——康威的生命游戏

python - 如何替换 "from IPython.kernel import KernelManager"?

Python 迭代器追加逻辑

python - 找不到满足 SoundRecognition 要求的版本

python-3.x - python 计算元组中的出现次数