title: Im trying to fit a custom function to some 1-D histogram data but I get - TypeError: only size-1 arrays can be converted to Python scalars
body: <p>Id like to fit a function to some data from a molecular dynamics simulation using the curve_fit function from Python 3. The raw data is a 40,000 row column specifying the end-to-end distance of an 11 residue polypeptide in water (btw). I want to fit a histogram of a subset of this data. This question is posted elsewhere on the forum and Ive tried to implement the ideas there but I havent been able to make it work. Here is the code and some output:</p>
  
  <pre><code>#take subset from 40000 frames
  ppII_etoe_wt = np.take(etoedist_wt_np, loc_ppII_wt)
  print(len(ppII_etoe_wt))
  print(ppII_etoe_wt[:5])
  
  1495
  [[16.273 ]
   [27.0817]
   [30.5083]
   [26.2768]
   [17.6271]]
  
  #make histogram bins and histograma 
  binedges_1D = np.arange(4,33.01,0.2)
  bincenters = 0.5*(binedges_1D[1:]+binedges_1D[:-1])  
  
  ppII_etoe_wt_hist = np.histogram(ppII_etoe_wt, binedges_1D)
  
  #fitting function
  def fit_function(x, C, t):
      return C*(float(x**2)/(1-x**2)**9.0/2) * np.exp(-0.75*t/(1-x**2))
  
  #convert histogram to numpy array
  ppII_etoe_wt_hist = np.array(ppII_etoe_wt_hist[0])
  
  print(np.shape(ppII_etoe_wt_hist))
  print(type(ppII_etoe_wt_hist))
  print(type(bincenters))
  print(np.shape(bincenters))
  
  (145,)
  &lt;class 'numpy.ndarray'&gt;
  &lt;class 'numpy.ndarray'&gt;
  (145,)
  
  #attempt to fit function
  popt = curve_fit(fit_function, bincenters, ppII_etoe_wt_hist)
  print(popt)
  
  TypeError: only size-1 arrays can be converted to Python scalarsTh
  </code></pre>