[Numpy-discussion] Request for enhancement to numpy.random.shuffle

Robert Kern robert.kern at gmail.com
Sun Oct 12 07:57:06 EDT 2014

On Sat, Oct 11, 2014 at 11:51 PM, Warren Weckesser
<warren.weckesser at gmail.com> wrote:

> A small wart in this API is the meaning of
>   shuffle(a, independent=False, axis=None)
> It could be argued that the correct behavior is to leave the
> array unchanged. (The current behavior can be interpreted as
> shuffling a 1-d sequence of monolithic blobs; the axis argument
> specifies which axis of the array corresponds to the
> sequence index.  Then `axis=None` means the argument is
> a single monolithic blob, so there is nothing to shuffle.)
> Or an error could be raised.
> What do you think?

It seems to me a perfectly good reason to have two methods instead of
one. I can't imagine when I wouldn't be using a literal True or False
for this, so it really should be two different methods.

That said, I would just make the axis=None behavior the same for both
methods. axis=None does *not* mean "treat this like a single
monolithic blob" in any of the axis=-having methods; it means "flatten
the array and do the operation on the single flattened axis". I think
the latter behavior is a reasonable interpretation of axis=None for
both methods.

Robert Kern

More information about the NumPy-Discussion mailing list