how to get a wrap aound slice of numpy array

Robert Kern robert.kern at
Fri Apr 20 23:29:57 CEST 2007

danfan1981 at wrote:
> Hi, I am learning Numpy and using it for a course project.

Welcome! You might want to ask more numpy questions on the numpy mailing list.
Answers to numpy questions here tend to be hit-or-miss.

> Suppose x = [0, 1, 2, 3, 4], I know that x[0:2] would give [0,1], and
> x[-1] give [4], is there a way that I can get [4,0,1]. I try x[-1:2],
> but it returns an empty array.

x[[-1, 0, 1]]

Robert Kern

"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 Python-list mailing list