1 year ago
#350615
Rowan Sidebottom
Pulling values from a piecewise function
I am trying to get values of a piecewise function of linearly spaced time points from an existing data set of times and positions. so if the dataset has time values of ts= 0,5,10,15 etc and I want them spaced at twant= 0,3,6,9 etc. the twant= 0,3 would have the xs value of 0, and 6,9 would have the xs value of 5, and so on and so forth. But I cannot get it to work, the code I have below would only give the correct values if ts =0,1,2,3,4 etc. what can I do to do this? like this
'''
ts = [0,5,10,15,20,25]
twant=[0,3,6,9,12,15]
xs= [1000,2000,3000,4000,5000,6000]
def getdata(tvalue, ts, xs):
xvals=[]
for i in tvalue:
for j in xs:
if j == i:
xvals.append(xs[j])
return xvals
getdata(twant, ts, xs)
Output --> (1000,4000)
python
for-loop
jupyter-notebook
enumerate
piecewise
0 Answers
Your Answer