how to get a wrap aound slice of numpy array

danfan1981 at yahoo.com danfan1981 at yahoo.com
Fri Apr 20 22:28:56 CEST 2007


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.




More information about the Python-list mailing list