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

  • SEARCH
  • Home
  • 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 8840301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:26:06+00:00 2026-06-14T10:26:06+00:00

I want to fit a function, defined as follows, to a time series data:

  • 0

I want to fit a function, defined as follows, to a time series data:

def func(t, a0, a1, a2, T, tau1, tau2):
    if t < T:
        return a0 + a1 * np.exp(-t/tau1) + a2 * np.exp(-t/tau2)
    else:
        return a0 + a1 * np.exp(-T/tau1) * (1 - t/tau1 + T/tau1) + a2 * np.exp(-T/tau2) * (1 - t/tau2 + T/tau2) 

Here, t represents the time at which a measurement is made, and the rest of the arguments are the parameters of the function. The problem is that when I feed it into curve_fit, Python complains about the ambiguity in the t < T comparison. I believe this happens because t becomes a list of data points when func is called inside curve_fit, whereas T is a number (not a list):

popt, pcov = curve_fit(func, t1, d1)

where t1 is a list of times and d1 is a list of the data values measured at the corresponding times. I have attempted a number of ways to get around this problem, but to no avail. Any suggestion? Thanks a lot!

  • 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-14T10:26:07+00:00Added an answer on June 14, 2026 at 10:26 am

    That’s right, t < T is a boolean array. NumPy refuses to assign a truth value to boolean arrays because there are many possible choices — should it be True if all elements are True, or if any element is True?

    But that’s okay. In this case, NumPy provides a nice function to replace the if ... else ... blocks, namely, np.where:

    def func(t, a0, a1, a2, T, tau1, tau2):
        return np.where(
            t < T,
            a0 + a1 * np.exp(-t/tau1) + a2 * np.exp(-t/tau2),
            a0 + a1 * np.exp(-T/tau1) * (1 - t/tau1 + T/tau1) + a2 * np.exp(-T/tau2) * (1 - t/tau2 + T/tau2) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to automatically fit time series returns into a NIG distribution. With nigfit()
I've a 1D list of data, that I want to fit into a distribution
I am trying to estimate missing values in time-series data which is in the
I want to write a function to downsize an image to fit specified bounds.
I have a bunch of data, and I want a fitting with a function
In python I have a function which has many parameters. I want to fit
I want to fit a curve using the lsqcurvefit function. It is something like
I want to fit every member of a list of data sets to a
I want to make a linear fit to few data points, as shown on
I want to fit a power function to a dataset. I'm using this method:

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.