【问题标题】:Scipy interpolation of numpy large array fails when exceeding a certain number of elements超过一定数量的元素时,numpy大数组的Scipy插值失败
【发布时间】:2015-03-05 09:56:28
【问题描述】:

我正在尝试分析时间序列中的数据。我想插入原始数据并使它们在时间上等距,所以我为此使用 scipy 三次样条。在达到 10000 点(浮点数)之前一切正常,但在达到这个点数之后似乎不起作用。我尝试了 10001 个点并且插值失败。是内存问题吗?我正在使用 Canopy(学术许可)。

# reading the timeseries and interpolating with cubic splines
# for creating  equally spaced in time data
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats.stats as st
from   scipy import interpolate
# Reading the timeseries data file as a two column ASCII file
data = np.loadtxt('cut.dat')
data_tot = np.loadtxt('mynrg.dat')
# creating the arrays of each observable
# 10000 has been set during my tests i want 65536 points
time = np.array(data[:10000,0]); 

heat_flux =np.array( data[:10000,1]);


#new time values equaly spaced
new_time_values = np.linspace(time[0], time[np.size(time)-1],endpoint=True,num = np.size(time));

# cubic spline interpolation
# plot original and interpolated data
spl_fit = interpolate.splrep(time , heat_flux, s =0 , k =3);
new_heat_flux = interpolate.splev(new_time_values, spl_fit, der=0);

【问题讨论】:

  • 你能发布一些你的代码吗?
  • 您是否收到错误消息?如果是这样,请您发布它(可能包括堆栈跟踪)?如果您没有收到错误消息,会发生什么?
  • 我正在绘制原始数据和插值数据以进行比较,当然,当我遇到此问题时,插值数据不会出现。我还从我试图用插值绘制的直方图中收到一条错误消息。当我检查 spl_fit 热通量(函数内部)的值时,它似乎具有 Nan 值,而当我检查它们的 heat_flux 数组时,它是好的。所有这些都从我使用 65536 点开始

标签: python numpy scipy


【解决方案1】:

样条拟合是一个全局过程。您的 splrep 调用尝试操作 10000 x 10000 矩阵。底层的 Fortran 代码发挥了一些相当聪明的技巧,但仍然 --- 你真的需要连续可微性吗?使用分段多项式插值器可能会更好(查看 scipy.interpolate.PPoly 和 BPoly)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多