[Numpy-discussion] random.choice

Nathaniel Smith njs at pobox.com
Fri Nov 9 12:21:13 EST 2012

On Fri, Nov 9, 2012 at 2:17 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> I just noticed that 1.7 is scheduled to add a random.choice function.
> I wonder if the best structure has been chosen.  Specifically, it does
> not provide for array flattening, and it does not provide for subarray
> choice.

I think in terms of the function currently in numpy master:

You write flattening as
  np.random.choice(a.ravel(), ...)
and subarray choice as
  np.take(a, np.random.choice(a.shape[ax], ...), axis=ax)

That said, since it (claims to) only work on 1-d arrays right now, we
could always add either or both of these features later without
breaking compatibility. So I don't think there's any urgent need to
fix this before releasing.

(If you're worried though then you might want to double-check that the
np.random.choice in 1.7 actually *does* give an error if the input
array is not 1-d.)


More information about the NumPy-Discussion mailing list