title: Gradient computation by convolution masks
body: <p>I need to compute the gradient of a matrix <code>(3,3)</code>, say <code>a=array([[1,4,2],[6,2,4],[7,5,1]])</code>.</p>
  
  <p>I simply use:</p>
  
  <pre><code>from numpy import *
  dx,dy = gradient(a)
  &gt;&gt;&gt; dx
     array([[ 5. , -2. ,  2. ],
     [ 3. ,  0.5, -0.5],
     [ 1. ,  3. , -3. ]])
  &gt;&gt;&gt; dy
  array([[ 3. ,  0.5, -2. ],
     [-4. , -1. ,  2. ],
     [-2. , -3. , -4. ]])
  </code></pre>
  
  <p>I know that a way for computing the gradient of a matrix is by convolution with a mask for each direction, but results are different</p>
  
  <pre><code>from scipy import ndimage
  mx=array([[-1,0,1],[-1,0,1],[-1,0,1]])
  my=array([[-1,-1,-1],[0,0,0],[1,1,1]])
  cx=ndimage.convolve(a,mx)
  cy=ndimage.convolve(a,my)
  &gt;&gt;&gt; cx
  array([[-2,  0,  2],
     [ 3,  7,  4],
     [ 8, 14,  6]])
  &gt;&gt;&gt; cy
  array([[ -8,  -5,  -2],
     [-13,  -6,   1],
     [ -5,  -1,   3]])
  </code></pre>
  
  <p>Where is the error?</p>