Re: [Numpy-discussion] Slice specified axis

2012-04-10 Thread Jonathan T. Niehof
On 04/09/2012 09:11 PM, Tony Yu wrote: I guess I wasn't reading very carefully and assumed that you meant a list of `slice(None)` instead of a list of `None`. My apologies to Ben...I wasn't being pedantic to be a jerk, I was being pedantic because I read Ben's message and thought oooh, that

Re: [Numpy-discussion] Slice specified axis

2012-04-10 Thread Benjamin Root
On Tue, Apr 10, 2012 at 12:52 PM, Jonathan T. Niehof jnie...@lanl.govwrote: On 04/09/2012 09:11 PM, Tony Yu wrote: I guess I wasn't reading very carefully and assumed that you meant a list of `slice(None)` instead of a list of `None`. My apologies to Ben...I wasn't being pedantic to be a

Re: [Numpy-discussion] Slice specified axis

2012-04-09 Thread Jonathan T. Niehof
On 04/06/2012 06:54 AM, Benjamin Root wrote: Take a peek at how np.gradient() does it. It creates a list of None with a length equal to the number of dimensions, and then inserts a slice object in the appropriate spot in the list. List of slice(None), correct? At least that's what I see in

Re: [Numpy-discussion] Slice specified axis

2012-04-09 Thread Benjamin Root
On Mon, Apr 9, 2012 at 12:14 PM, Jonathan T. Niehof jnie...@lanl.govwrote: On 04/06/2012 06:54 AM, Benjamin Root wrote: Take a peek at how np.gradient() does it. It creates a list of None with a length equal to the number of dimensions, and then inserts a slice object in the appropriate

Re: [Numpy-discussion] Slice specified axis

2012-04-09 Thread Tony Yu
On Mon, Apr 9, 2012 at 12:22 PM, Benjamin Root ben.r...@ou.edu wrote: On Mon, Apr 9, 2012 at 12:14 PM, Jonathan T. Niehof jnie...@lanl.govwrote: On 04/06/2012 06:54 AM, Benjamin Root wrote: Take a peek at how np.gradient() does it. It creates a list of None with a length equal to the

Re: [Numpy-discussion] Slice specified axis

2012-04-06 Thread Benjamin Root
On Friday, April 6, 2012, Val Kalatsky wrote: The only slicing short-cut I can think of is the Ellipsis object, but it's not going to help you much here. The alternatives that come to my mind are (1) manipulation of shape directly and (2) building a string and running eval on it. Your

Re: [Numpy-discussion] Slice specified axis

2012-04-06 Thread Tony Yu
On Fri, Apr 6, 2012 at 8:54 AM, Benjamin Root ben.r...@ou.edu wrote: On Friday, April 6, 2012, Val Kalatsky wrote: The only slicing short-cut I can think of is the Ellipsis object, but it's not going to help you much here. The alternatives that come to my mind are (1) manipulation of

Re: [Numpy-discussion] Slice specified axis

2012-04-06 Thread Matthew Brett
Hi, On Fri, Apr 6, 2012 at 1:12 PM, Tony Yu tsy...@gmail.com wrote: On Fri, Apr 6, 2012 at 8:54 AM, Benjamin Root ben.r...@ou.edu wrote: On Friday, April 6, 2012, Val Kalatsky wrote: The only slicing short-cut I can think of is the Ellipsis object, but it's not going to help you much

[Numpy-discussion] Slice specified axis

2012-04-05 Thread Tony Yu
Is there a way to slice an nd-array along a specified axis? It's easy to slice along a fixed axis, e.g.: axis = 0: array[start:end] axis = 1: array[:, start:end] ... But I need to do this inside of a function that accepts arrays of any dimension, and the user can operate on any axis of the

Re: [Numpy-discussion] Slice specified axis

2012-04-05 Thread Val Kalatsky
The only slicing short-cut I can think of is the Ellipsis object, but it's not going to help you much here. The alternatives that come to my mind are (1) manipulation of shape directly and (2) building a string and running eval on it. Your solution is better than (1), and (2) is a horrible hack,