我正在研究测量HRV(心率变异性)分析的程序,但是出现以下错误。
from scipy.interpolate import interp1d
meaures = [peaklist]
print('this peaklist is for measuring of frequency domain maesures', peaklist)
RR_x = peaklist[1:]
print('RR_X IS : ', RR_x)
RR_y = RR_interval_list
print('RR_Y IS : ', RR_y)
RR_x_new = np.linspace(RR_x[0], RR_x[-1],RR_x[-1])
print("RR_X_NEW IS : ", RR_x_new)
f = interp1d(RR_x_new, RR_y, kind='cubic')
print('f is : ',f(250))
此峰列表用于测量频域测量值
[63, 165, 264, 360, 460, 565, 674, 773, 863, 953, 1048, 1156, 1272, 1385, 1487, 1592, 1698, 1803, 1897, 1994, 2097, 2206, 2308, 2406]
RR_X IS:
[165, 264, 360, 460, 565, 674, 773, 863, 953, 1048, 1156, 1272, 1385, 1487, 1592, 1698, 1803, 1897, 1994, 2097, 2206, 2308, 2406]
RR_Y是:
[1020.0, 990.0, 960.0, 1000.0, 1050.0, 1090.0, 990.0, 900.0, 900.0, 950.0, 1080.0, 1160.0, 1130.0, 1020.0, 1050.0, 1060.0, 1050.0, 940.0, 970.0, 1030.0, 1090.0, 1020.0, 980.0]
RR_X_NEW IS:
[ 165. 165.93180873 166.86361746 ... 2404.13638254 2405.06819127
2406. ]
回溯(最近通话最近):文件 “ C:/Users/Dee1/PycharmProjects/HeartAna1.1/HeartAna.py”,第235行,在 f = interp1d(RR_x_new,RR_y,kind ='cubic')文件“ C:\ ProgramData \ Anaconda3 \ envs \ HeartAna1.1 \ lib \ site-packages \ scipy \ interpolate \ interpolate.py”, 第433行,在 init _Interpolator1D。初始化(自身,x,y,轴=轴)文件“ C:\ ProgramData \ Anaconda3 \ envs \ HeartAna1.1 \ lib \ site-packages \ scipy \ interpolate \ polyint.py” , 第60行,初始化 self.set_yi(yi,xi = xi,axis = axis)文件“ C:\ ProgramData \ Anaconda3 \ envs \ HeartAna1.1 \ lib \ site-packages \ scipy \ interpolate \ polyint.py”, set yi中的第125行 引发ValueError(“ x和y数组的长度必须沿” ValueError相等:x和y数组的长度必须沿插值相等 轴。
以退出代码1完成的过程
答案 0 :(得分:0)
这不是interp1d
设计的工作方式。 x
和y
参数必须具有相同的长度。以您的示例为例,您要做的是:
import numpy as np
from scipy.interpolate import interp1d
RR_x = [165, 264, 360, 460, 565, 674, 773, 863, 953, 1048, 1156, 1272, 1385, 1487, 1592, 1698, 1803, 1897, 1994, 2097, 2206, 2308, 2406]
RR_y = [1020.0, 990.0, 960.0, 1000.0, 1050.0, 1090.0, 990.0, 900.0, 900.0, 950.0, 1080.0, 1160.0, 1130.0, 1020.0, 1050.0, 1060.0, 1050.0, 940.0, 970.0, 1030.0, 1090.0, 1020.0, 980.0]
f = interp1d(RR_x, RR_y, kind='cubic')
RR_x_new = np.linspace(RR_x[0], RR_x[-1], RR_x[-1])
RR_y_new = f(RR_x_new)
print(RR_y_new)
# array([1020. , 1020.07989053, 1020.14949355, ..., 979.18255462, 979.58047408, 980. ])