How do you convert a reading between two calibration points?
interp linearly blends adjacent sample values according to position on an increasing coordinate grid.
numpy.interp in practice
Between calibration points (0,10) and (4,30), input one maps to 15. Outside the grid, the defaults hold the endpoint values, so extending the line requires a separate policy.
import numpy as np
np.interp([-1,1,5],[0,4],[10,30])Result [10.0, 15.0, 30.0]
中文
两个标定点之间的读数怎样换算?
interp 在递增坐标上的相邻样点间进行线性插值,按相对距离混合两端的值。
numpy.interp 算例
标定点 (0,10) 和 (4,30) 之间,输入 1 映射为 15。默认超出范围会返回相邻端点值,延长直线需另行指定算法。
import numpy as np
np.interp([-1,1,5],[0,4],[10,30])结果 [10.0, 15.0, 30.0]