numpy.random.triangular

random.triangular(left, mode, right, size=None)

从间隔的三角形分布中提取样本 [left, right] .

三角形分布是一个连续的概率分布,有左下限、模式峰值和右上限。与其他分布不同,这些参数直接定义PDF的形状。

注解

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

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

下限。

mode浮点数或类似浮点数的数组

分布峰值出现的值。值必须满足条件 left <= mode <= right .

right浮点数或类似浮点数的数组

上限,必须大于 left .

sizeint或int的元组,可选

输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 leftmoderight 都是鳞片。否则, np.broadcast(left, mode, right).size 取样。

返回
outndarray或scalar

从参数化三角分布中提取样本。

参见

Generator.triangular

应该用于新代码。

笔记

三角形分布的概率密度函数是

System Message: WARNING/2 (P(x;l,m,r)=\begin{cases})

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) ! LaTeX Error: \begin{split} on input line 14 ended by \end{equation*}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! 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.15 \end{equation*} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! 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.15 \end{equation*} ! LaTeX Error: \begin{cases} on input line 15 ended by \end{split}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Missing \right. inserted. <inserted text> \right . l.15 \end{equation*} ! 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.15 \end{equation*} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! 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.15 \end{equation*} ! LaTeX Error: \begin{cases} on input line 15 ended by \end{split}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.15 \end{equation*} ! Missing \right. inserted. <inserted text> \right . l.15 \end{equation*} ! LaTeX Error: \begin{equation*} on input line 13 ended by \end{document}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.16 \end{document} ! Missing $ inserted. <inserted text> $ l.16 \end{document} ! Missing } inserted. <inserted text> } l.16 \end{document} ! Missing } inserted. <inserted text> } l.16 \end{document} ! Missing } inserted. <inserted text> } l.16 \end{document} ! Missing \cr inserted. <inserted text> \cr l.16 \end{document} ! Missing { inserted. <inserted text> { l.16 \end{document} ! Missing { inserted. <inserted text> { l.16 \end{document} ! Extra }, or forgotten $. <recently read> } l.16 \end{document} ! Missing $ inserted. <inserted text> $ l.16 \end{document} ! Missing } inserted. <inserted text> } l.16 \end{document} (./math.aux) ! You can't use `\end' in internal vertical mode. \enddocument ... \endgroup \deadcycles \z@ \@@end l.16 \end{document} ! LaTeX Error: \begin{equation*} on input line 13 ended by \end{document}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.16 \end{document} ! Missing } inserted. <inserted text> } l.16 \end{document} ! Missing $ inserted. <inserted text> $ l.16 \end{document} ! Display math should end with $$. <to be read again> \endgroup l.16 \end{document} ) ! Emergency stop. <*> math.tex No pages of output. Transcript written on math.log.

三角分布常被用于定义不清的问题中,这些问题的基本分布是未知的,但存在一些关于极限和模式的知识。通常用于模拟。

工具书类

1

维基百科,“三角形分布”https://en.wikipedia.org/wiki/triangular_distribution

实例

从分布中绘制值并绘制柱状图:

>>> import matplotlib.pyplot as plt
>>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200,
...              density=True)
>>> plt.show()
../../../_images/numpy-random-triangular-1.png