title: wrapping around slices in Python / numpy
body: <p>I have a numpy array, and I want to get the "neighbourhood" of the i'th point. Usually the arrays I'm using are two-dimensional, but the following 1D example illustrates what I'm looking for. If</p>
  
  <pre><code>A = numpy.array([0,10,20,30,40,50,60,70,80,90])
  </code></pre>
  
  <p>Then the (size 5) neighbourhood of element 4 is <code>[20,30,40,50,60]</code>, and this can easily be obtained by doing <code>A[i-2:i+3]</code>. </p>
  
  <p>However, I also need the neighbourhoods to "wrap around" the edges of the array, so that the neighbourhood of the element 0 is <code>[80,90,0,10,20]</code> and the neighbourhood of the element 9 is <code>[70,80,90,0,10]</code>. I can't seem to find an elegant way to do this, so I end up having to use some complicated, annoying logic every time this comes up (which is very often for me). In the 2D case the neighbourhood of a point would be a rectangular array.</p>
  
  <p>So my question is, is there a neat way to expres this "wrap-around neighbourhood" operation in numpy? I would prefer something that returns a slice rather than a copy, but readability and speed are the most important considerations.</p>