[SciPy-dev] numpy.random.randint

Alan G Isaac aisaac at american.edu
Fri Mar 10 12:26:47 CST 2006


> 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.

I do not think any of the numpy distributions have a competing 'shape'
parameter, but if so that just makes the situation *worse*.

A user's opinion,
Alan Isaac






More information about the Scipy-dev mailing list