title: NumPy ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() leastsq
body: <pre><code>from sympy import *
  from scipy import *
  from scipy.integrate import quad
  import scipy.optimize as optimize
  import numpy as np
  import collections
  import math
  from scipy.optimize import leastsq
  
  file= DATA+'Union21.dat'
  with open(file, "r") as f:
      data0=[(float(v[1]),float(v[2]), float(v[3])) for v in [x.split() for x in f.readlines()][1:]]
  #print data0
  
  z=np.array([float(t[0]) for t in data0])
  mu=np.array([float(t[1]) for t in data0])
  dmu=np.array([float(t[2]) for t in data0])
  c=3*10^8
  
  def calka(x, OmM):
      return 1./math.sqrt(OmM*(1.+x)**3 + (1.-OmM))
  
  def xlambda(p,xup): 
      H0=p
      calka1 = quad(calka, 0., xup, args=(p[0]))[0]
      mu_obs = 5.*math.log(c*calka1/p[1]) + 25 
      return mu_obs
  
  
  def residuals(p, xup,y,dmu):
      return ((y-xlambda(p,xup))/dmu)**2
  
  leastsq(residuals,(0.25, 70), args=(z, mu, dmu))
  </code></pre>
  
  <p>Thank you for your answer but now there was a problem:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call     last)
  TypeError: Cannot cast array data from dtype('complex128') to     dtype('float64') according to the rule 'safe'
  
  ---------------------------------------------------------------------------
  error                                     Traceback (most recent call     last)
  &lt;ipython-input-38-00c118ea80ce&gt; in &lt;module&gt;()
  ----&gt; 1 leastsq(residuals,[0.25, 70], args=(z, mu, dmu))
  
  /opt/anaconda/envs/np18py27-1.9/lib/python2.7/site-packages/scipy    /optimize/minpack.pyc in leastsq(func, x0, args, Dfun, full_output,     col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)
  377             maxfev = 200*(n + 1)
  378         retval = _minpack._lmdif(func, x0, args, full_output, ftol, xtol,
  --&gt; 379                                  gtol, maxfev, epsfcn, factor, diag)
  380     else:
  381         if col_deriv:
  
  error: Result from function call is not a proper array of floats.
  </code></pre>
  
  <p>I try change dtype array from complex128 to float64 but it didn't help :(</p>
  
  <p>I looking for maybe np.interp but i don't know which array a i must change</p>
  
  <p>Can you any idea what i have to do?</p>