title: replicating borders in 2d numpy arrays
body: <p>I am trying to replicate the border of a 2d numpy array:</p>
  
  <pre><code>&gt;&gt;&gt; from numpy import *
  &gt;&gt;&gt; test = array(range(9)).reshape(3,3)
  array([[0, 1, 2],
         [3, 4, 5],
         [6, 7, 8]])
  </code></pre>
  
  <p>Is there an easy way to replicate a border in any direction?</p>
  
  <p>for example:</p>
  
  <pre><code>&gt;&gt;&gt;&gt; replicate(test, idx=0, axis=0, n=3) 
  array([[0, 1, 2],
         [0, 1, 2],
         [0, 1, 2],
         [0, 1, 2],
         [3, 4, 5],
         [6, 7, 8]])
  </code></pre>
  
  <p><strong>edit</strong>:</p>
  
  <p>the following function did the job:</p>
  
  <pre><code>def replicate(a, xy, se, n):
      rptIdx = numpy.ones(a.shape[0 if xy == 'X' else 1], dtype=int)
      rptIdx[0 if se == 'start' else -1] = n + 1
      return numpy.repeat(a, rptIdx, axis=0 if xy == 'X' else 1)
  </code></pre>
  
  <p>with xy in ['X', 'Y'] and se in ['start', 'end']</p>