[SciPy-dev] stats confusion
josef.pktd at gmail.com
josef.pktd at gmail.com
Wed Jun 17 09:37:10 EDT 2009
On Wed, Jun 17, 2009 at 9:27 AM, Neal Becker<ndbecker2 at gmail.com> wrote:
> josef.pktd at gmail.com wrote:
>
>> On Wed, Jun 17, 2009 at 8:23 AM, Neal Becker<ndbecker2 at gmail.com> wrote:
>>> I'm still finding stats usage confusing. The doc
>>>
> (http://docs.scipy.org:80/doc/scipy/reference/generated/scipy.stats.chi2.html?highlight=chi2#scipy.stats.chi2)
>>>
>>> says:
>>>
>>> chi2.cdf(x,df,loc=0,scale=1) :
>>>
>>> And even has an example:
>>> prb = chi2.cdf(x,df)
>>>
>>> But if df is given as keyword:
>>> scipy.stats.chi2.cdf(1, df=2)
>>> ERROR: An unexpected error occurred while tokenizing input
>>> The following traceback may be corrupted or invalid
>>> The error message is: ('EOF in multi-line statement', (1331, 0))
>>>
>>>
> ---------------------------------------------------------------------------
>>> TypeError Traceback (most recent call
>>> last)
>>>
>>> /home/nbecker/globalstar/<ipython console> in <module>()
>>>
>>> /usr/lib64/python2.6/site-packages/scipy/stats/distributions.pyc in
>>> cdf(self, x, *args, **kwds)
>>> 623 if any(cond): #call only if at least 1 entry
>>> 624 goodargs = argsreduce(cond, *((x,)+args))
>>> --> 625 place(output,cond,self._cdf(*goodargs))
>>> 626 if output.ndim == 0:
>>> 627 return output[()]
>>>
>>> TypeError: _cdf() takes exactly 3 arguments (2 given)
>>>
>>> What's going on here? Do stats not accept keyword args as per normal
>>> python usage?
>>>
>>
>> As the signature indicates df is a positional argument and not a
>> keyword argument
> The doc says:
>
> chi2.cdf(x,df,loc=0,scale=1)
>
> A python user would then expect chi2.cdf (x=0, df=1) to work. Isn't there a
> problem with that doc? Is it not feasible to fix this so these functions
> behave as a naive python user would expect?
Positional arguments cannot be called as keyword arguments, that is
standard python.
(on the other hand keyword arguments can be called also as positional arguments.
the signature and help has standard notation:
eg. signature: np.maximum(x1, x2[, out])
>>> np.maximum(x1=[5], x2=[6])
Traceback (most recent call last):
TypeError: 'x2' is an invalid keyword to maximum
>>> np.maximum([5],[6])
array([6])
Josef
More information about the SciPy-Dev
mailing list