title: 2D interpolation and maximum with interp2d and fmin/minimize from scipy
body: <p>I have some data from the lab to analyze. Until now it was a problem which was dependend on one variable. Therefore I found a solution (<a href="http://kitchingroup.cheme.cmu.edu/blog/category/interpolation/" rel="nofollow noreferrer">http://kitchingroup.cheme.cmu.edu/blog/category/interpolation/</a>):</p>
  
  <pre><code># use splines to fit and interpolate data
  from scipy.interpolate import interp1d
  from scipy.optimize import fmin
  import numpy as np
  
  x = np.array([ 0,      1,      2,      3,      4    ])
  y = np.array([ 0.,     0.308,  0.55,   0.546,  0.44 ])
  
  # create the interpolating function
  f = interp1d(x, y, kind='cubic', bounds_error=False)
  
  # to find the maximum, we minimize the negative of the function. We
  # cannot just multiply f by -1, so we create a new function here.
  f2 = interp1d(x, -y, kind='cubic')
  xmax = fmin(f2, 2.5)
  
  [...]
  </code></pre>
  
  <p>It figured out that my problem is dependend on at least two parameters. So I tried to apply "interp2d" for a multidimensional problem. But in fact I did not understand how do that exactly.</p>
  
  <p>I have a matrix of data for testing which is like:</p>
  
  <pre><code>     | 2.00 | 2.50 | 3.00 | 3.50 | ...
  --------------------------------------
  5.00 | 0.0  | 60.0 | 10.0 | 0.00
  10.0 | 0.0  | 100.0| 70.0 | 30.0
  25.0 | 10.0 | 40.0 | 50.0 | 10.0
  50.0 | 15.0 | 30.0 | 10.0 | 0.0
  ...
  </code></pre>
  
  <p>I read this post "<a href="https://stackoverflow.com/questions/3057015/scipy-interpolation-on-a-numpy-array">Scipy interpolation on a numpy array</a>" which was quite interesting for me. It's now possible for me to interpolate data like in the example. But I don't know how to apply a function like "minimize" from scipy. There is an example (<a href="http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize" rel="nofollow noreferrer">http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize</a>) but the use a analytical function instead of an interpolated dataset like in the 1D example above.</p>
  
  <pre><code>res = minimize(func, x0, method='Nelder-Mead')
  </code></pre>
  
  <p>When I tried to use interp2d to do it the same way I got into trouble because of the shape of the array. Maybe it is the key to solve the problem to use it?</p>
  
  <p>Maybe someone can explain to me how to use such a 2D interpolation and how to find the maximum.</p>
  
  <p>Regards,
  Alex</p>