[Numpy-discussion] getitem and slice

Keith Goodman kwgoodman at gmail.com
Mon Nov 15 09:57:01 EST 2010


There is more than one way to form the same slice. For example, a[:2]
and a[0:2] and a[0:2:] pass slice objects to getitem with the same
start, stop and step. Is there any way to get a hold of the exact
character sequence the user used to form the slice? That is, I'd like
to know if the user entered ":2", "0:2" or "0:2:".

Context:

Say I have a 2d array-like object with axis 0 named 'space' and axis 1
named 'time', I'd like to be able to make the following distinctions:

a['time':2] --> a[:,2]
a['time':2:] --> a[:,2:]

a['space':2] --> a[2]
a['space':2:] --> a[2:]



More information about the NumPy-Discussion mailing list