简体   繁体   中英

interpolate to larger 1D array using python

I have five 1D array with multiple length.I want all the arrays to have the same length as cD1 . I want to apply interpolation on the arrays to have the same length. I've attempted to use linear_interp = interp1d(cD5, cD1) , but it doesn't work properly. Any help is appreciated!

from scipy.interpolate import interp1d
coeffs = wavedec(data, 'sym5', level=5)
cA5,cD5,cD4,cD3,cD2,cD1=coeffs
cD5.shape #(248,)
cD4.shape #(488,)
cD3.shape #(967,)
cD2.shape #(1926,)
cD1.shape #(3844,)

As far as I can tell you are missing an x coordinate.

Try to add a common x coordinate for your arrays:

import numpy as np
from scipy.interpolate import interp1d

common_length_data = []
common_x = np.linspace(0, 1, len(cD1))
for c in [cA5,cD5,cD4,cD3,cD2,cD1]:
    x = np.linspace(0, 1, len(c))
    f = interp1d(x, c)
    common_length_data.append(f(common_x))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM