title: Numpy gradient of 2D array
body: <p>I have a 2D array that is a sinusoidal pattern and I want to plot both the x and y gradient of that function.</p>
  
  <p>From some previous function I have a 2D array called 'image_data', e.g:</p>
  
  <pre><code>def get_image(params):
      # do some maths on params
      return(image)
  
  params = (a, b, c)
  image_data = get_image(params)
  </code></pre>
  
  <p>I then use <code>numpy.gradient</code> on the image to get the gradients:</p>
  
  <pre><code>gradients = numpy.gradient(image_data)
  x_grad = gradients[0]
  y_grad = gradients[1]
  </code></pre>
  
  <p>Plotting all three looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/luoVX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/luoVX.png" alt="gradients"></a></p>
  
  <p>But I'm not sure if it's correct. Because this pattern not at 45 degrees, I'd expect the x and y gradients to be different.</p>
  
  <p>In my mind, <code>x_gradient[i][j]</code> should be the gradient of <code>image_data[i][j]</code> with respect to the indexes either side, whilst <code>y_gradient[i][j]</code> should be the gradient with respect to the indexes above and below.</p>
  
  <p>Because the pattern is angled slightly, you can see in <code>image_data</code> that the gradient of the function changes at different rates. </p>
  
  <p>Am I misinterpreting my data or not understanding the numpy.gradient output?</p>
  
  <p>Thanks!</p>