[SciPy-dev] numpy.random.randint
Robert Kern
robert.kern at gmail.com
Fri Mar 10 12:45:26 CST 2006
Alan G Isaac wrote:
>>Johannes Löhnert wrote:
>>
>>>I just noticed that in function numpy.random.randint, the
>>>shape=... keyword was replaced by size=...
>
>
>>>I find this somewhat counterintuitive, as it denotes
>>>the shape of the desired array (as tuple),
>>>although it also takes integer values. Also it is an
>>>unnecessary break with backwards compatibility (to RandomArray).
>
>
>>>I would suggest to allow both "shape" & "size", with
>>>"shape" having precedence.
>
>
> On Fri, 10 Mar 2006, Robert Kern apparently wrote:
>
>>It was a choice for compatibility with the scipy PRNGs all of which use "size".
>>"shape" was not a good argument name because many of the probability
>>distributions have a "shape" parameter.
>
>
>>I don't think it's wise to make more ways to do exactly
>>the same thing.
>
> But this is really horrible:
>
> >>> import numpy as N
> >>> x = N.random.standard_normal(size=(3,2))
> >>> x.size
> 6
> >>> x.shape
> (3, 2)
> >>> x = N.random.standard_normal(shape=(3,2))
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'shape' is an invalid keyword argument for this function
>
> Since numpy is less than version 1, this really should be
> changed for consistency, and allowing both for a while with
> a deprecation warning on 'size' is reasonable.
The keyword in the functions does not necessarily match with the attribute names
on the objects. I don't find this particularly shocking. Or bad. But that's just
my tastes.
So I'm -1 on changing numpy.random and all of scipy.stats.
> I do not think any of the numpy distributions have a competing 'shape'
> parameter, but if so that just makes the situation *worse*.
I also avoided the "shape" terminology for the "shape" parameters, too, to avoid
conflation. However, a lot of the probability distributions do have a "shape"
parameter. lognormal, gamma, beta, pareto, and on and on and on. Anything that
isn't a location or a scale parameter is called a shape parameter in probability
theory.
--
Robert Kern
robert.kern at gmail.com
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Scipy-dev
mailing list