python - 在一维序列的大列表上的 Scipy 二次一维插值非常慢
问题描述
我有一个一维序列的大列表(500 000+),我想对它们中的每一个进行二次插值。由于它们的大小不同,我不得不遍历它们并在每个序列上应用 scipy.interpolate.interp1D 。它非常慢,我正在寻找一种方法来解决问题。
目前,我有以下功能:
def interp_sequences(sequences, max_len):
'''Interpolate sequences in order to reduce their length to max_len
sequences (list of numpy arrays): The sequences to interpolate
maxlen (int): The maximum length of the sequence: All sequences will be interpolated to match this length
-------------------------------------------------------------------
returns (ndarray): The interpolated sequences
'''
interp_obs = np.zeros((len(obs_list), 5, 120))
# Looping is dirty... But the sequences have different lengths...
for idx, s in enumerate(sequences):
original_len = s.shape[1]
f = interp1d(np.arange(original_len), s, 'quadratic', axis = 1)
interp_seq = np.apply_along_axis(f, 0, np.linspace(0, original_len -1, num = max_len))
interp_obs[idx] = interp_seq
return interp_obs
我也尝试过使用不会提高性能的列表理解。我想使用 numba-scipy 但它目前不支持插值。先感谢您 !
解决方案
推荐阅读
- java - 关联分配游标结果集问题
- reactjs - 是否有用于反应的 buefy 等效包?
- javascript - javascript中如何实现调用一个函数自动调用另一个函数
- google-sheets - 插入行时,有没有办法使用数组公式来保留我的公式(添加特定列)?
- reactjs - 汉堡菜单下拉到 xs 调整大小的新行
- codenameone - 检测 Codename One 轻量级日期选择器上的“取消”按下
- sql - SQL Server:使用聚集索引导入大数据
- excel - VBA 公式在第二个空格后删除所有内容
- python - 将 groupby 函数与 .csv 文件中的数据框一起使用并绘制结果
- html - 网页未正确呈现