title: Minimize function with Scipy minimize
body: <p>Trying to obtain the d value (integer) for which the Std_Diff objective function is minimal, using Scipy minimize. </p>
  
  <p>My code:</p>
  
  <pre><code>def Std_Diff(d):
      return std(diff(df['BN'].values,d));
  
  from scipy.optimize import minimize
  b=(3,)
  res = minimize(Std_Diff,(1,), method='SLSQP', bounds = b)
  
  The **df['BN'].values** are 
  Out[72]: 
  array([ 2,  2,  2,  2,  3,  2,  7,  5,  7, 11,  8,  2, 11,  7, 15,  8,  7,
         12, 21, 19, 32, 35, 40, 35, 21, 19, 25, 20, 40, 80, 99], dtype=int64)
  </code></pre>
  
  <p>Error is</p>
  
  <blockquote>
    <p>IndexError: too many indices for array</p>
  </blockquote>
  
  <p>In case I do not use <code>bounds</code>:</p>
  
  <pre><code>res = minimize(Std_Diff,(1,), method='SLSQP')
  </code></pre>
  
  <p>I get another error: </p>
  
  <pre><code>&gt; in _minimize_slsqp(func, x0, args, jac, bounds, constraints, maxiter,
  &gt; ftol, iprint, disp, eps, callback, **unknown_options)
  &gt;     368                 fx = float(np.asarray(func(x)))
  &gt;     369             except:
  &gt; --&gt; 370                 raise ValueError("Objective function must return a scalar")
  &gt;     371             # Compute the constraints
  &gt;     372             if cons['eq']: ValueError: Objective function must return a scalar.
  </code></pre>