Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:55:53+00:00 2026-06-14T06:55:53+00:00

When I try to do an exponential fit using curve_fit, scipy returns an error.

  • 0

When I try to do an exponential fit using curve_fit, scipy returns an error. Am I doing something wrong? Removing the negative sign from np.exp(-b * t) allows curve_fit to work, but the values it returns are way off.

#!/usr/bin/python                                                                   

import numpy as np                                                                  
import scipy as sp  
from scipy.optimize import curve_fit                                                                                                                                                                                                       
import scipy.optimize as opt                                                        
import matplotlib.pyplot as plt                                                     

x = [40,45,50,55,60]                                                                
y = [0.99358851674641158, 0.79779904306220106, 0.60200956937799055, 0.49521531100478472, 0.38842105263157894]

def model_func(t, a, b, c):                                                         
    return a * np.exp(-b * t) + c                                                   

opt_parms, parm_cov = sp.optimize.curve_fit(model_func, x, y, maxfev=1000)          
a,b,c = opt_parms                                                                   
print a,b,c                                                                         
print x                                                                             
print y                                                                             
print model_func(x, a,b,c)         

Fails with error:

  Traceback (most recent call last):
      File "asdf.py", line 18, in <module>
        opt_parms, parm_cov = sp.optimize.curve_fit(model_func, x, y, maxfev=1000)
      File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 426, in curve_fit
        res = leastsq(func, p0, args=args, full_output=1, **kw)
      File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 276, in leastsq
        m = _check_func('leastsq', 'func', func, x0, args, n)[0]
      File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 13, in _check_func
        res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
      File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 346, in _general_function
        return function(xdata, *params) - ydata
    ValueError: operands could not be broadcast together with shapes (0) (5) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:55:54+00:00Added an answer on June 14, 2026 at 6:55 am

    change x and y to numpy arrays

    x = np.array([40,45,50,55,60])
    y = np.array([0.99358851674641158, 0.79779904306220106, 0.60200956937799055, 0.49521531100478472, 0.38842105263157894])
    

    then I think you are good, because the function requires vectorized computation, whereas lists are not adequate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
try: return [ True, errors[error], error ] # Error found except SoapFault as e:
try { using (MapDataContainer ent = new MapDataContainer()) //is an autogen'd EF object {
Try to use npm install libxml and an error : Failed at the libxml@0.0.5
try { $dbh = new PDO('mysql:host=localhost;dbname=wqposts', 'root', ''); $query = SELECT wqpid FROM threads
Try the following in python 2.6: newyear_2012 = datetime.date.fromtimestamp(1325419200) newyear.year # returns 2012 newyear.isocalendar()
Using ICU 4.0 regex library, I find that the following regex is exhibiting exponential
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I'm trying to implement retry logic with exponential backoff using NSTimer. My code looks
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.