📜  numpy.interp()函数Python

📅  最后修改于: 2022-05-13 01:54:41.458000             🧑  作者: Mango

numpy.interp()函数Python

numpy.interp()函数将一维分段线性插值返回给具有给定离散数据点 (xp, fp) 的函数,在 x 处求值。

代码#1:

# Python program explaining
# numpy.interp() function
       
# importing numpy as geek 
import numpy as geek 
   
x = 3.6
xp = [2, 4, 6]
fp = [1, 3, 5]
   
gfg = geek.interp(x, xp, fp)
  
print (gfg)

输出 :

2.6


代码#2:

# Python program explaining
# numpy.interp() function
       
# importing numpy as geek 
import numpy as geek 
   
x = [0, 1, 2.5, 2.72, 3.14]
xp = [2, 4, 6]
fp = [1, 3, 5]
   
gfg = geek.interp(x, xp, fp)
  
print (gfg)

输出 :

[1.   1.   1.5  1.72 2.14]