[Numpy-discussion] Slice specified axis

Jonathan T. Niehof jniehof at lanl.gov
Mon Apr 9 12:14:44 EDT 2012


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]])

-- 
Jonathan Niehof
ISR-3 Space Data Systems
Los Alamos National Laboratory
MS-D466
Los Alamos, NM 87545

Phone: 505-667-9595
email: jniehof at lanl.gov

Correspondence /
Technical data or Software Publicly Available



More information about the NumPy-Discussion mailing list