linear interpolation between two data points

前端 未结 3 960
我寻月下人不归
我寻月下人不归 2021-01-13 02:33

I have two data points x and y:

  x = 5 (value corresponding to 95%)
  y = 17 (value corresponding to 102.5%)

No

3条回答
  •  -上瘾入骨i
    2021-01-13 03:31

    You can use numpy.interp function to interpolate a value

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = [95, 102.5]
    y = [5, 17]
    
    x_new = 100
    
    y_new = np.interp(x_new, x, y)
    print(y_new)
    # 13.0
    
    plt.plot(x, y, "og-", x_new, y_new, "or");
    

提交回复
热议问题