title: Python fsolve shape of fprime is wrong?
body: <p>The following could not be much simpler, yet I cannot find how to make it work...</p>
  
  <pre><code>from scipy.optimize import fsolve
  
  def a(x):
      return x*x-x
  
  def ap(x):
      return 2*x-1
  
  #works
  print(fsolve(a, 0.3))
  
  #works
  print(fsolve(a, 0.3, fprime=ap))
  
  #works
  print(fsolve(a, [0.3], fprime=ap))
  
  #works
  print(fsolve(a, [0.3, 0.7]))
  
  #crashes
  print(fsolve(a, [0.3, 0.7], fprime=ap))
  </code></pre>
  
  <p>When it crashes is gives the error</p>
  
  <pre><code>TypeError: fsolve: there is a mismatch between the input and output shape of the 'fprime' argument 'ap'.Shape should be (2, 2) but it is (2,).
  </code></pre>
  
  <p>The output dimension of <code>ap</code> seems like it should definitely be the same as the input. How could this possibly be going wrong (and how do I fix it)?</p>
  
  <p>I think some downvoters are missing the subtlety of the question so here is a more in depth explanation of why I am confused:</p>
  
  <p>It seems that scipy interprets <code>a</code> as a function of one variable with <code>[0.3,0.7]</code> starting estimates of two roots in <code>fsolve(a, [0.3, 0.7])</code>, but in <code>fsolve(a, [0.3, 0.7], fprime=ap)</code> it interprets <code>a</code> as function of two variables with <code>[.3,.7]</code> being the estimate of a single root. According to the documentation (<a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html" rel="nofollow noreferrer">https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html</a>), the second argument </p>
  
  <pre><code>x0 : ndarray
      The starting estimate for the roots of func(x) = 0.
  </code></pre>
  
  <p>says that it is looking for estimate of the roots (<strong>plural</strong>). But its behavior in the case where <code>fprime</code> is given makes it sound like <code>x0</code> is interpreted as an estimate of a single root.</p>