[SciPy-user] Internal parameter changes while appending scipy.stats function to a list
Wei Xie
weixie2007 at gmail.com
Wed Apr 22 13:12:18 EDT 2009
Dear Scipy users:
While playing SCIPY (numpy version 1.3.0, scipy version 0.7.0, windows), it
seems sometimes the internal parameters change quite unexpectedly. For
example,
>>> from scipy.stats import norm
>>> from numpy.random import normal
>>> e = []
>>> e.append((1,lambda q:norm.ppf(q,loc=1,scale=0.1),lambda
sz=1:normal(loc=1,scale=0.1,size=sz)))
>>> e.append((10,lambda q:norm.ppf(q,loc=10,scale=0.1),lambda
sz=1:normal(loc=10,scale=0.1,size=sz)))
>>> e.append((100,lambda q:norm.ppf(q,loc=100,scale=0.1),lambda
sz=1:normal(loc=100,scale=0.1,size=sz)))
This one works as
>>> e[0][1](0.5)
1.0
>>> e[1][1](0.5)
10.0
>>> e[2][1](0.5)
100.0
suggests the internal location parameters still holds the value as assigned.
On the other hand:
>>> d = []
>>> for i in (1,10,100): d.append((i,lambda
q:norm.ppf(q,loc=i,scale=0.1),lambda sz=1:normal(loc=i,scale=0.1,size=sz)))
does not work, as
>>> d[0][1](0.5)
100.0
>>> d[1][1](0.5)
100.0
>>> d[2][1](0.5)
100.0
suggess the internal loc parameters to 100.0, i.e., the last one.
I am a bit puzzled by this finding as I am expecting lambda expression will
give me a closure and therefore the internal parameter loc and scale should
not change.
I am looking forward to your input. Thanks.
Wei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090422/ddf543e9/attachment.html>
More information about the SciPy-User
mailing list