[Numpy-discussion] getitem and slice
Mon Nov 15 09:23:04 CST 2010
On Mon, Nov 15, 2010 at 08:57, Keith Goodman <firstname.lastname@example.org> wrote:
> 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.
Not quite correct. a[:2] passes slice(None, 2, None) whereas the next
two pass slice(0, 2, None).
> 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:".
No, there is no way to get this information.
> 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
> a['space':2:] --> a[2:]
Sorry, [i:j] is semantically equivalent to [i:j:].
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion