[SciPy-User] scipy.stats.norm strange doc string
nicky van foreest
vanforeest at gmail.com
Sun Mar 13 15:52:49 EDT 2011
Hi,
The doc string of scipy.stats.norm tells me that the location and
scale parameters are array-like. However, when I try to pass arrays to
the loc and scale keywords I get an error. Specifically:
In [1]: from scipy.stats import norm
In [2]: import numpy as np
In [3]: mu = np.array([1,1])
In [4]: simga = np.array([1,1])
In [5]: x = [0,1,2,3]
In [6]: norm.pdf(x, loc = mu, scale = simga)
results in :
ValueError: shape mismatch: objects cannot be broadcast to a single shape
I do understand how to resolve this problem, but for my specific
purpose I would have liked to pass mu and sigma as arrays, that is, I
would have liked to achieve
tau = np.zeros([g,m])
for i in range(g):
tau[i] = p[i]*norm.pdf(x, loc=mu[i], scale = sigma[i])
in one pass.
BTW:
I am using this code to fit a set of normal distributions to a given
(quite) general distribution function by using the EM algorithm. Is
this already coded somewhere in scipy? If not, is somebody interested
in me making this available on the scipy cookbook?
bye
Nicky
More information about the SciPy-User
mailing list