numpy.random.chisquare

random.chisquare(df, size=None)

从卡方分布中提取样本。

什么时候? df 独立随机变量,每一个都有标准正态分布(平均值0,方差1),是平方和总和,得到的分布是卡方分布(见注释)。这种分布通常用于假设检验。

注解

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

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

自由度数必须大于0。

sizeint或int的元组,可选

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

返回
outndarray或scalar

从参数化卡方分布中提取样本。

加薪
ValueError

什么时候? df <=0或当 size (例如) size=-1 )。

参见

Generator.chisquare

应该用于新代码。

笔记

通过平方和得到的变量 df 独立的标准正态分布随机变量:

Q=\sum_i=0 ^ \mathtt df x^2_i

卡方分布,表示

Q \sim \chi^2_k.

卡方分布的概率密度函数是

System Message: WARNING/2 (p(x)=\frac{(1/2)^{k/2}}{\Gamma(k/2)})

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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\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 ...�1/2)^{k/2}}{\Gamma(k/2)}\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 440 bytes). Transcript written on math.log.

在哪里? \Gamma 是伽玛函数,

System Message: WARNING/2 (\伽玛(x)=\int-\infty t x-1 e-t dt.)

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) ! Undefined control sequence. <argument> \split@tag \begin {split}\� ��玛(x)=\int -\infty t x-1 e-t dt... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BC. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BD. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Unicode character 玛 (U+739B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\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 ...�x)=\int-\infty t x-1 e-t dt.\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 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Undefined control sequence. <argument> \split@tag \begin {split}\� ��玛(x)=\int -\infty t x-1 e-t dt... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BC. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Invalid UTF-8 byte "BD. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\end{split} ! Package inputenc Error: Unicode character 玛 (U+739B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...�x)=\int-\infty t x-1 e-t dt.\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 ...�x)=\int-\infty t x-1 e-t dt.\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 ...�x)=\int-\infty t x-1 e-t dt.\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 412 bytes). Transcript written on math.log.

工具书类

1

NIST“工程统计手册”https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm

实例

>>> np.random.chisquare(2,4)
array([ 1.89920014,  9.00867716,  3.13710533,  5.62318272]) # random