title: Scipy optimize fmin ValueError: setting an array element with a sequence
body: <p>When using <code>scipy.optimize</code>'s <code>fmin</code> I'm getting an error I don't understand: </p>
  
  <pre><code>ValueError: setting an array element with a sequence.
  </code></pre>
  
  <p>Here's a simple squared error example to demonstrate:</p>
  
  <pre><code>import numpy as np
  from scipy.optimize import fmin
  
  def cost_function(theta, X, y):    
      m = X.shape[0]
      error = X.dot(theta) - y 
      J = 1/(2*m) * error.T.dot(error)  
      return J
  
  X = np.array([[1., 1.],
                [1., 2.],
                [1., 3.],
                [1., 4.]])
  
  y = np.array([[2],[4],[6],[8]])   
  initial_theta = np.ones((X.shape[1], 1)) * 0.01
  
  # test cost_function
  print cost_function(initial_theta, X, y)
  # [[ 14.800675]] seems okay...
  
  # but then error here...   
  theta = fmin(cost_function, initial_theta, args=(X, y))
  
  #Traceback (most recent call last):
  #  File "C:\Users\me\test.py", line 21, in &lt;module&gt;
  #    theta = fmin(cost_function, initial_theta, args=(X, y))
  #  File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 278, in fmin
  #    fsim[0] = func(x0)
  #ValueError: setting an array element with a sequence.
  </code></pre>
  
  <p>I'd be grateful for any help to explain where I'm going wrong.</p>