0

I am trying to fit a dataset in which I want my fitting model to account for two different intervals of my data (i.e.: I want to fit two different regions of my dataset, let's the first 10 elements of a list and the 30 last ones).

To fit a specific interval within a list,I usually write the following:

p2, cov2 = scipy.optimize.curve_fit(scatter2,wv[0:121],ab[0:121],p0=p_guess2, absolute_sigma=True, maxfev=90000, method='lm') 
    a2, b2=p2

However, since I am looking to fit an extra region of data, I wanted to write in a pythonic way something of the following:

wv[0:121]+[461:481] #(I know this is not written properly)

What is then the proper way to call two different regions of a list?

Thank you in advance for all the help!

I have tried to google, but I am probably not googling the write terms to find the answer. I have also just tried to do the fitting by calling my list as

wv[0:121][461:481]

, but this did not work either.

Dory
  • 1

1 Answers1

0

Think this answer might have good options / approaches for your problem:

  • Numpy np.r_

    import numpy as np
    np.r_[1:4, 6:11]
    #array([ 1,  2,  3,  6,  7,  8,  9, 10])
    
  • itertools.chain function.

top rated is using range and unpack (* operator)

x = [*range(1, 4), *range(6, 11)]

but as mentioned in the comments this produces the list in memory. So if your actual list is rather small this might be ok. Otherwise itertools.chain might be the better option.

klaas
  • 1,661
  • 16
  • 24