title: how to get the neighboring elements in a numpy array with taking boundaries into account?
body: <p>I want to get the neighbors of the certain element in the numpy array. Lets consider following example</p>
  
  <pre><code>    a = numpy.array([0,1,2,3,4,5,6,7,8,9])
  </code></pre>
  
  <p>So I want to specify position 5 and want to get three neighbors from both sides. It can be done</p>
  
  <pre><code>   index = 5
     num_neighbor=3
     left = a[index-num_neighbor:index]
     right= a[num_neighbor+1:num_neighbor+index+1]
  </code></pre>
  
  <p>The above code does not take care of the boundaries... I want that i get the neighbours within the boundaries of the array. For this consider the following example if index is 1 then the left neighbor is only one element which is 0.</p>
  
  <p>Thanks a lot</p>