1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Matlabのnormpdf()をpythonで

Posted at

何かとお世話になるガウシアンの書き方。
scipyのstatsを使うのが良さそう。

matlabで平均M,分散SのXでのPDFはnormpdf(X,M,S)で求める。
同じことは、scipt.stats.norm.pdf(X,M,S)でできる。

例:normpdf() in Matlab

>> normpdf(-2:0.5:2,0,1)

ans =

    0.0540    0.1295    0.2420    0.3521    0.3989    0.3521    0.2420    0.1295    0.0540

例:scipy.stats.norm.pdf() in Python

>>> from scipy import stats
>>> import numpy as np
>>> stats.norm.pdf(np.arange(-2,2,0.5),0,1)
array([0.05399097, 0.1295176 , 0.24197072, 0.35206533, 0.39894228,
       0.35206533, 0.24197072, 0.1295176 ])

ほとんど一緒。

other than normal?

ここでは正規分布を扱ったので、stats.normだったけど、
このnormを色々と変えると、ポアソンやらガンマやら、色々な分布を同じように扱えるらしい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?