[Numpy-discussion] Allowing 0-d arrays in np.take
Benjamin Root
ben.root at ou.edu
Tue Dec 4 09:15:45 EST 2012
On Tue, Dec 4, 2012 at 8:57 AM, Sebastian Berg
<sebastian at sipsolutions.net>wrote:
> Hey,
>
> Maybe someone has an opinion about this (since in fact it is new
> behavior, so it is undefined). `np.take` used to not allow 0-d/scalar
> input but did allow any other dimensions for the indices. Thinking about
> changing this, meaning that:
>
> np.take(np.arange(5), 0)
>
> works. I was wondering if anyone has feelings about whether this should
> return a scalar or a 0-d array. Typically numpy prefers scalars for
> these cases (indexing would return a scalar too) for good reasons, so I
> guess that is correct. But since I noticed this wondering if maybe it
> returns a 0-d array, I thought I would ask here.
>
> Regards,
>
> Sebastian
>
>
At first, I was thinking that the output type should be based on what the
input type is. So, if a scalar index was used, then a scalar value should
be returned. But this wouldn't be true if the array had other dimensions.
So, perhaps it should always be an array. The only other option is to
mimic the behavior of the array indexing, which wouldn't be a bad choice.
Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121204/738e6cb9/attachment.html>
More information about the NumPy-Discussion
mailing list