how to get a wrap aound slice of numpy array

D

danfan1981

Hi, I am learning Numpy and using it for a course project.
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.

I am doing convolution (e.g. convolve [0, 1, 2, 3, 4] with [1,-2,1])
with wrap-around boundary condition, so sometimes the indices would
wrap around the boundaries, and sometimes not. I would like to find a
generic expression for both cases.
 
R

Robert Kern

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.

http://www.scipy.org/Mailing_Lists
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top