[Numpy-discussion] Slice specified axis
Benjamin Root
ben.root at ou.edu
Mon Apr 9 12:22:32 EDT 2012
On Mon, Apr 9, 2012 at 12:14 PM, Jonathan T. Niehof <jniehof at lanl.gov>wrote:
> 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 the source,
> and:
>
> >>> a = numpy.array([[1,2],[3,4]])
> >>> operator.getitem(a, (None, slice(1, 2)))
> array([[[3, 4]]])
> >>> operator.getitem(a, (slice(None), slice(1, 2)))
> array([[2],
> [4]])
>
>
Correct, sorry, I was working from memory.
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120409/7dab3aa6/attachment.html>
More information about the NumPy-Discussion
mailing list