[Numpy-discussion] fix random.choice for 1.7?

Nathaniel Smith njs at pobox.com
Mon Nov 12 17:46:10 EST 2012

On Mon, Nov 12, 2012 at 11:34 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> On 11/12/2012 12:16 PM, Sebastian Berg wrote:
>> So instead of taking a sequence of length 1, take an element as default.
> Sebastien has proposed that np.random.choice return
> a single *element* by default, not a 1d array of length 1.
> He proposes to associate this with a default value of `size=None`.
> The motivation: it is more natural, and in particular,
> it would behave more like Python's random.choice by default.
> This decision should be made before this function
> is part of a release.

I see, so right now we have

  >>> np.random.choice([1, 2, 3])

but you're suggesting

  >>> np.random.choice([1, 2, 3])
  >>> np.random.choice([1, 2, 3], size=1)

That does seem like an obvious improvement to me, since all the other
random functions work that way, e.g.:

In [2]: np.random.normal()
Out[2]: -0.8752867990041713

In [4]: np.random.normal(size=1)
Out[4]: array([ 1.92803487])

Want to make a pull request?


More information about the NumPy-Discussion mailing list