- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我觉得这是一个愚蠢的问题,但是当我在 IPython 笔记本中时,我确实在一些 numpy/scipy 函数上提供帮助,比如 stat.norm.rvs,它经常说,关于 *args 和 ** kargs,“有关更多信息,请参阅实例对象的文档字符串”。如果没有帮助(stat.norm.rvs),我如何查看此文档字符串?
最佳答案
不要觉得自己傻;有时很难找到您正在寻找的信息,尤其是刚开始时。此外,scipy.stats
中的大部分文档字符串都是自动生成的,因此它们有些通用,而不是定制的。好消息是,一旦您了解了如何操纵分布,所有其他的基本相同,因为它们共享相同的界面。
让我们来看一个例子。由于您使用的是 IPython(太棒了!),我们也可以在宾语后使用问号,例如obj?
,了解更多关于目的。这显示了文档字符串,如 help(obj)
,以及其他有用的信息,例如作为其类型、定义位置和(对于可调用对象)其调用签名。
了解事物的组织方式很有帮助。 scipy.stats
是一个模块:
In [386]: from scipy import stats
模块文档字符串列出了多种分布。
In [394]: stats?
...
Continuous distributions
========================
...
alpha -- Alpha
anglit -- Anglit
arcsine -- Arcsine
beta -- Beta
betaprime -- Beta Prime
...
norm -- Normal (Gaussian)
有两个主要类 -- stats.rv_continuous
和 stats.rv_discrete
。stats
文档字符串中列出的每个发行版都是一个实例这两个类之一。 stats.norm
例如,是一个 instance ofstats.norm_gen
这是一个 subclass of stats.rv_continuous
:
In [14]: type(stats.norm).mro()
Out[14]:
[scipy.stats._continuous_distns.norm_gen,
scipy.stats._distn_infrastructure.rv_continuous,
scipy.stats._distn_infrastructure.rv_generic,
object]
请注意 stats.norms.rvs
是一个实例方法:
In [387]: stats.norm.rvs?
Type: instancemethod
String form: <bound method norm_gen.rvs of <scipy.stats._continuous_distns.norm_gen object at 0x7f1479ba2690>>
所以稍后它会说
The shape parameter(s) for the distribution (see docstring of the instance object for more information).
它说在stats.norm
的文档字符串中有更多信息:
In [401]: stats.norm?
Docstring:
A normal continuous random variable.
The location (loc) keyword specifies the mean.
The scale (scale) keyword specifies the standard deviation.
...
Methods
-------
``rvs(loc=0, scale=1, size=1, random_state=None)``
Random variates.
从这个描述中,您可以看到 stats.norm.rvs(loc=10, scale=2, size=5)
将返回 5 个随机变量,均值为 10,标准差为 2:
In [402]: stats.norm.rvs(loc=10, scale=2, size=5)
Out[402]: array([ 9.82454792, 8.52106712, 7.33889233, 8.73638555, 10.90927226])
或者,stats.norm
也是可调用的——您可以传递 loc
和 scale
“形状”参数 to "freeze" those parameters进入分配。你得到的东西被称为“卡住分配”。例如,您可以创建一个均值为 10 且标准差为 2 的正态分布:
In [403]: norm = stats.norm(10, 2)
现在调用卡住分布的rvs
方法来获得5个随机变量:
In [404]: norm.rvs(5)
Out[404]: array([ 7.21018883, 12.98978919, 10.99418761, 11.2050962 , 8.27780614])
关于scipy - "see docstring of the instance object for more information"是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36391970/
我是 Python 的新手(来自 C++),在 Brackets 中运行一些测试代码。现在 pylint 提示说: C0111 > Missing module docstring [missing-
我正在写一个宏,它需要一个函数名, 并声明了该函数的几个其他版本。 我想为这些变体提供与原始方法相同的文档字符串, 也许有一些变化。 为此,我需要检索原始方法的文档字符串。 所以我要找的是一个函数:
我正在尝试编写一个列表输出,并将其扩展为 doctest 中的多行。但实际输出与我的预期并不相符。 这是我的代码。 def make_board(dimension: int, queens: lis
在下面的代码中: def read_file(filename): """ >>> read_file('text.txt') {'Donald Trump': [('Dona
为什么字节字符串 b'string' 不能用作类或函数的文档字符串(从某种程度上说我猜是模块)? 恰当的例子: >>> class Foo: ... b"""My Foo class for
我正在编写一个需要调用脚本文档字符串的模块。到目前为止,我已经设法使用 获取了调用脚本的文件名 import inspect filename = inspect.stack()[1].filenam
我想在我的命令行应用程序中获取文档字符串,但每次我调用内置的 help() 函数时,Python 都会进入交互模式。 如何获取对象的文档字符串并且不让 Python 获取焦点? 最佳答案 任何文档字符
我使用 Google-Style Python Docstring 格式已有一段时间了。我一直在处理没有参数的函数/方法的方式突然对我来说看起来不正确。我做了一些搜索,但在网上找不到任何说明如何处理这
如何将代码嵌入到文档字符串中,以告诉 Sphinx 格式化代码,就像在 Markdown 中所做的一样(不同的背景颜色,等宽的无字体)?例如记录一个代码使用示例。 """ This is a modu
我知道 Racket 不像许多其他语言那样具有“文档字符串”,但考虑到在源代码记录事物的便利性,我想在 Racket 中近似类似的东西。 当我第一次了解 Scribble 和#langs 时,我认为可
我有一个带有函数、文档字符串和文档测试的 Julia 模块文件。我加载它并在 Julia 帮助中显示文档字符串,但 Documenter.jl 找不到文档字符串。 一个示例模块文件,src/my_mo
我正在查看某人的代码,其中到处都是这种“文档字符串”: SLEEP_TIME_ON_FAILURE = 5 """Time to keep the connection open in case of
在尝试遵循我的 DocString 的 NumpyDoc 格式时,我似乎无法弄清楚如何告诉用户参数是关键字参数(即指定为 SomeFunc(theKeyWordArg=100) 而不是 SomeFun
我使用 PyCharm IDE 来协助制作符合 PEP0257 的文档字符串。它提供了两个属性,我不完全理解它们之间的区别/用途: :raise Exception: 此处异常说明 :raises E
我正在尝试正确配置 emacs 来编写我的 Clojure 代码。我的 Emacs 配置基于此 good blog post . 但是,我确实更改了一些设置,例如他正在使用的主题等。我一直在检查以获取
在 Python 中,在对函数进行注释时,可以采用一种更容易自动生成文档的方式。他们将其称为文档字符串。 现在我已经在 Groovy 中创建了一个我想传递的抽象类,是否有一种标准的方式我也应该对其进行
当使用 ?f 或 help(f) 通过 REPL 检查时,用户定义的函数(例如 f)如何具有有意义的打印输出 例如假设我写了以下函数 function f(x::Float64, y::Float64
epydoc 和 Sphinx 文档生成器都允许编码器注释任何/所有函数参数的类型。 我的问题是:当 记录 文档字符串。这不会是strong-typing(编译时检查),但(更有可能)可能被称为fir
我正在尝试添加帮助文本以在我的 python 脚本中运行,类似于为 input() 或 print() 打开括号时的情况。 Docstrings 做类似的事情,但在编写代码时没有用。 请看下图我想要的
谁能告诉我以下文档字符串参数之间的区别? :type 和 :param我见过两者都被用来指定方法参数的类型,但我认为它们的作用并不完全相同。其中一个用于程序员,另一个用于 IDE 或类似的东西吗? :
我是一名优秀的程序员,十分优秀!