I am doing interpolation for some lists.
Some of my data is out of the range, how could I make a simple limit to solve this problem?
For example, one of my list look like this:
testList = [[(0.0, -0.9960135495794032), (0.5, -1.0)], [(0.5, -1.0), (2.0, -0.16138322487766676), (2.5, 1.0849272141417852)]]
I would like to do interpolation to find (x, y=0) and (x, y=-1).
I know for the left part [(0.0, -0.9960135495794032), (0.5, -1.0)]
is out of the range for (x, y=0).
How could edit my code to make the result which list is out of the range directly equals to (x= 0, y=0)?
This is my code:
from scipy import interpolate
res_j = []
for j in range(0, 2, 1):
res_k = []
for k in range(0, 2, 1):
testList = [
[[(0.0, -0.9960135495794032), (0.5, -1.0)], [(0.5, -1.0), (2.0, -0.16138322487766676), (2.5, 1.0849272141417852)]],
[[(4.0, 3.3149805356833015), (4.5, 0.1649293864654484), (5.0, -1.0)], [(5.0, -1.0), (5.5, 0.33841349597101744), (6.0, 4.702347949145297)]],
]
x = [c[0] for c in testList[j][k]]
y = [c[1] for c in testList[j][k]]
# Enter y to find x: f(y) = x
f = interpolate.interp1d(y, x)
interpolate_result = (f(0), f(-1))
res_k.append(interpolate_result)
res_j.append(res_k)
print(res_j)
I am trying to get the result like:
[[(array(0), array(0.5)), (array(2.06474439), array(0.5))], [(array(4.57078944), array(5.)), (array(5.37357663), array(5.))]]