python - 这个 SciPy 教程指的是什么 python 函数?

标签 python numpy scipy

SciPy 的网站有一个引用 python 函数 source 的教程,其中列出了用 python 编写的函数的源代码,但我无法在 python 中使用它或在线找到它的文档。引用在this底部页。我看到 inspect 模块具有类似的功能,但我仍然很好奇它们引用的是哪个模块中的哪个函数。

最佳答案

np.sourcenumpy 中的实用函数。这可以在任何 numpy/scipy 或 Python 函数或类上调用,尽管编译的内置函数不会显示任何内容。

scipy 和 numpy API 文档还有一个 [source] 链接,可将您带到源文件。

我认为 np.source 相对较新,但作为一个长期的 ipython 用户,我已经通过它的 ?? 魔力获得了相同的信息。

np.source(np.source) 给我

def source(object, output=sys.stdout):
    """
    ...
    """
    # Local import to speed up numpy's import time.
    import inspect
    try:
        print("In file: %s\n" % inspect.getsourcefile(object), file=output)
        print(inspect.getsource(object), file=output)
    except:
        print("Not available for this object.", file=output)

In [425]: np.source?? 显示相同的内容,但带有一些颜色编码。

关于python - 这个 SciPy 教程指的是什么 python 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44836250/

相关文章:

目录中的 Python 最新文件

Python 2.6 - 解析参数

python - 如何在 pypi 上为新项目创建 API token ?

python - 使用 numpy 读取自定义格式的日期时间

python - Pandas OneHotEncoder.fit(dataframe) 返回 ValueError : invalid literal for long() with base 10

python - 了解 matplotlib xticks 语法

Python拟合均匀分布

python - sqlalchemy 空架构且没有表

python - Tensorflow 中是否有用于改组或置换张量的内置函数?

python - 在 python 中嵌套数值积分