title: Python scipy fsolve "mismatch between the input and output shape of the 'func' argument"
body: <p>Before I go into my problem, I've searched the relevant threads on stackoverflow with the same problem:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/10505378/input-output-error-in-scipy-optimize-fsolve">input/output error in scipy.optimize.fsolve</a></li>
  <li><a href="https://stackoverflow.com/questions/21734602/python-fsolve-complains-about-shape-why">Python fsolve() complains about shape. Why?</a></li>
  <li><a href="https://stackoverflow.com/questions/22413454/fsolve-mismatch-between-input-and-output">fsolve - mismatch between input and output</a></li>
  <li><a href="https://stackoverflow.com/questions/27073407/i-o-shape-mismatch-when-using-scipy-optimize-fsolve-on-2-dimensional-anonymous-f">I/O shape mismatch when using scipy.optimize.fsolve on 2-dimensional anonymous function array variable</a></li>
  </ul>
  
  <p>From what I understand reading about this error,  </p>
  
  <blockquote>
    <p>raise TypeError(msg)<br>
    TypeError: fsolve: there is a mismatch between the input and output shape of the 'func' argument 'fsolve_function'</p>
  </blockquote>
  
  <p>The issue is that the shape of the input and output are <em>not</em> the same. </p>
  
  <p>In my code example below, I have the following: </p>
  
  <ul>
  <li>input, <code>initialGuess</code> (the starting estimate to be used in the <code>fsolve</code> function in scipy.optimize). The input, <code>initialGuess</code> has 3 starting estimates for coordinates x,y and z. Therefore I expect my starting input estimate to have always three inputs.</li>
  <li>output, <code>out</code> (non-linear simultaneous equations). In this example I have 4 non-linear equations.</li>
  <li><code>scipy.optimize.fsolve</code> raises the error highlighted above, because the input and output do <em>not</em> have the same shape. In my particular case, I want my input to always have three values (to guess the initial starting points of x, y, and z). The output in this case has 4 non-linear equations to solve using the initial input estimate.</li>
  <li>Side note: Using the same input and output shape, eg. input shape of 3 [x, y, z] and output of 3 non-linear equations, <code>fsolve</code> will do the calculation accordingly. I'm just wondering how could you extend <code>fsolve</code> to use let's say equal or more than 4 non-linear simultaneous equations with just 3 input initial estimates?</li>
  <li><p>Code below:</p>
  
  <pre><code>from scipy.optimize import fsolve
  
  def fsolve_function(arguments):
      x = arguments[0]
      y = arguments[1]
      z = arguments[2]
  
      out = [(35.85 - x)**2 + (93.23 - y)**2 + (-39.50 - z)**2 - 15**2]
      out.append((42.1 - x)**2 + (81.68 - y)**2 + (-14.64 - z)**2 - 27**2)
      out.append((-70.90 - x)**2 + (-55.94 - y)**2 + (-68.62 - z)**2 - 170**2)
      out.append((-118.69 - x)**2 + (-159.80 - y)**2 + (-39.29 - z)**2 - 277**2)
  
      return out
  
  initialGuess = [35, 93, -39]
  result = fsolve(fsolve_function, initialGuess)
  print result 
  </code></pre></li>
  </ul>