numpy.random.RandomState.geometric

方法

random.RandomState.geometric(p, size=None)

从几何分布中提取样本。

伯努利试验是两种结果中的一种:成功或失败(这种试验的一个例子是掷硬币)。几何分布模拟了为取得成功必须进行的试验次数。因此,正整数支持它, k = 1, 2, ... .

几何分布的概率质量函数是

System Message: WARNING/2 (f(k)=(1-p)^ k-1 p)

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...split}f(k)=(1-p)^ k-1 p\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 408 bytes). Transcript written on math.log.

在哪里? p 是个体试验成功的概率。

注解

新代码应该使用 geometric A方法 default_rng() 请参阅 快速启动 .

参数
p浮点数或类似浮点数的数组

个体试验成功的概率。

sizeint或int的元组,可选

输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 p 是标量。否则, np.array(p).size 取样。

返回
outndarray或scalar

从参数化几何分布中提取样本。

参见

Generator.geometric

应该用于新代码。

实例

从几何分布中得出一万个值,个体成功的概率等于0.35:

>>> z = np.random.geometric(p=0.35, size=10000)

一次测试成功了多少次?

>>> (z == 1).sum() / 10000.
0.34889999999999999 #random