[Numpy-discussion] Use-case for np.choose

David Goldsmith d.l.goldsmith at gmail.com
Sat Nov 7 19:53:13 EST 2009

Thanks, Anne.

On Sat, Nov 7, 2009 at 1:32 PM, Anne Archibald <peridot.faceted at gmail.com>wrote:

> 2009/11/7 David Goldsmith <d.l.goldsmith at gmail.com>:


> > Also, my experimenting suggests that the index array ('a', the first
> > argument in the func. sig.) *must* have shape (choices.shape[-1],) -
> someone
> > please let me know ASAP if this is not the case, and please furnish me w/
> a
> > counterexample because I was unable to generate one myself.
> It seems like a and each of the choices must have the same shape

So in essence, at least as it presently functions, the shape of 'a'
*defines* what the individual choices are within 'choices`, and if 'choices'
can't be parsed into an integer number of such individual choices, that's
when an exception is raised?

> (with
the exception that choices acn be scalars), but I would consider this
> a bug.

OK, then we definitely need more people to opine on this, because, if the
the two don't match, our established policy is to document *desired*
behavior, not extant behavior (and file a bug ticket).

> Really, a and all the choices should be broadcast to the same
> shape. Or maybe it doesn't make sense to broadcast a - it could be

Thus begging the question: does anyone actually have an extant, specific

> valuable to know that the result is always exactly the same shape as a
> - but broadcasting all the choice arrays presents an important
> improvement of choose over fancy indexing.

Then perhaps we need either another function, or a flag specifying which
behavior this one should exhibit.

> There's a reason choose
> accepts a sequence of arrays as its second argument, rather than a
> higher-dimensional array.

And that reason is probably supposed to be transparent above, but I've
confused it by this point, so can you please reiterate it here, in so many
words. :-)

Thanks again,


> Anne
> > Thanks,
> >
> > DG
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20091107/d3a6cda3/attachment.html>

More information about the NumPy-Discussion mailing list