title: how to fit a step function in python
body: <p>I have a question about fitting a step function using scipy routines like curve_fit. I have trouble making it vectorized, for example:</p>
  
  <pre><code>import numpy as np
  from scipy.optimize import curve_fit
  import matplotlib.pyplot as plt
  
  xobs=np.linspace(0,10,100)
  yl=np.random.rand(50); yr=np.random.rand(50)+100
  yobs=np.concatenate((yl,yr),axis=0)
  
  def model(x,rf,T1,T2):
  #1:   x=np.vectorize(x)
      if x&lt;rf:
          ret= T1
      else:
          ret= T2
      return ret
  #2: model=np.vectorize(model)
  popt, pcov = curve_fit(model, xobs, yobs, [40.,0.,100.])
  </code></pre>
  
  <p>It says </p>
  
  <pre><code>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p>If I add #1 or #2 it runs but doesn't really fit the data:</p>
  
  <pre><code>OptimizeWarning: Covariance of the parameters could not be estimated     category=OptimizeWarning)
  [ 40.          50.51182064  50.51182064] [[ inf  inf  inf]
  [ inf  inf  inf]
  [ inf  inf  inf]]
  </code></pre>
  
  <p>Anybody know how to fix that? THX</p>