[Numpy-discussion] Allowing slices as arguments for ndarray.take

sebastian sebastian at sipsolutions.net
Fri Jan 17 04:12:00 EST 2014

On 2014-01-17 00:28, Stephan Hoyer wrote:
> There was a discussion last year about slicing along specified axes in
> numpy arrays:
> http://mail.scipy.org/pipermail/numpy-discussion/2012-April/061632.html
> [1]
> I'm finding that slicing along specified axes is a common task for me
> when writing code to manipulate N-D arrays.
> The method ndarray.take basically does what I would like, except it
> cannot take slice objects as argument. In the mean-time, I've written
> a little helper function:
> def take(a, indices, axis):
>     index = [slice(None)] * a.ndim
>     index[axis] = indices
>     return a[tuple(index)]
> Is there support for allowing the `indices` argument to `take` to take
> Python slice objects as well as arrays? That would alleviate the need
> for my helper function.
> Cheers,
> Stephan
> Links:
> ------
> [1] 
> http://mail.scipy.org/pipermail/numpy-discussion/2012-April/061632.html

Personally, I am not sure that generalizing take is the right approach. 
Take is currently orthogonal to indexing implementation wise and has 
some smaller differences. Given a good idea for the api, I think a new 
function maybe better. Since I am not on a computer at the moment I did 
not check the old discussions though.

- Sebastian
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list