I have a 2D numpy array containing x (data[:,0]) and y(data[:,1]) information for a plot.
I’d like to fit a curve to the data, but only using certain parts of the data to determine the fitting parameters (e.g. using data in the range x = x1 -> x2, and x3 -> x4). My plan to do this is to create a new numpy array only containing the data I intend to pass to a SciPy CurveFitting routine.
index_range1 = np.where((data[:,0] > x1) and (data[:,0] < x2)
index_range2 = np.where((data[:,0] > x3) and (data[:,0] < x4)
and then I'd use these index ranges to pull the data of interest into a new array which I could pass to CurveFit.
Firstly, given that Python can handle complex arrays, this seems a very un-pythonic approach. Secondly, when running my script, I get an error saying that I need to use .any() or .all() in my expression for index_range 1 and 2.
I wonder, therefore, if anyone has any suggestions for an improved, more pythonic approach to solving this problem.
Thanks!