interpolation

Interpolation and extrapolation for large arrays

邮差的信 提交于 2020-01-13 03:21:26
问题 I have a large array y defined on a non-uniform, ordered grid x . The length of the array is typically N~2^14 to N~2^18. I want to get a spline-interpolation (or quadratic) of the array. The problem I am facing is that even for lower values of N the interpolation takes very long. import numpy as np from scipy.interpolate import interp1d N = 2 ** 12 # = 4096 x = np.linspace(0, 2*np.pi, N) y = np.sin(x) %time f = interp1d(x, y, 'cubic', ) CPU times: user 8min 5s, sys: 1.39 s, total: 8min 7s

`ValueError: A value in x_new is above the interpolation range.` - what other reasons than not ascending values?

放肆的年华 提交于 2020-01-12 14:25:45
问题 I receive this error in scipy interp1d function. Normally, this error would be generated if the x was not monotonically increasing. import scipy.interpolate as spi def refine(coarsex,coarsey,step): finex = np.arange(min(coarsex),max(coarsex)+step,step) intfunc = spi.interp1d(coarsex, coarsey,axis=0) finey = intfunc(finex) return finex, finey for num, tfile in enumerate(files): tfile = tfile.dropna(how='any') x = np.array(tfile['col1']) y = np.array(tfile['col2']) finex, finey = refine(x,y,0

`ValueError: A value in x_new is above the interpolation range.` - what other reasons than not ascending values?

强颜欢笑 提交于 2020-01-12 14:25:28
问题 I receive this error in scipy interp1d function. Normally, this error would be generated if the x was not monotonically increasing. import scipy.interpolate as spi def refine(coarsex,coarsey,step): finex = np.arange(min(coarsex),max(coarsex)+step,step) intfunc = spi.interp1d(coarsex, coarsey,axis=0) finey = intfunc(finex) return finex, finey for num, tfile in enumerate(files): tfile = tfile.dropna(how='any') x = np.array(tfile['col1']) y = np.array(tfile['col2']) finex, finey = refine(x,y,0

Is there a Java data structure that is effectively an ArrayList with double indicies and built-in interpolation?

做~自己de王妃 提交于 2020-01-12 07:55:08
问题 I am looking for a pre-built Java data structure with the following characteristics: It should look something like an ArrayList but should allow indexing via double-precision rather than integers. Note that this means that it's likely that you'll see indicies that don't line up with the original data points (i.e., asking for the value that corresponds to key "1.5"). EDIT : For clarity, based on the comments, I'm not looking to change the ArrayList implementation. I'm looking for a similar

Interpolation between two values in a single query

吃可爱长大的小学妹 提交于 2020-01-11 13:06:21
问题 I want to calculate a value by interpolating the value between two nearest neighbours. I have a subquery that returns the values of the neighbours and their relative distance, in the form of two columns with two elements. Let's say: (select ... as value, ... as distance from [get some neighbours by distance] limit 2) as sub How can I calculate the value of the point by linear interpolation? Is it possible to do that in a single query? Example: My point has the neighbour A with value 10 at

How do I delay expansion of variables in PowerShell strings?

倖福魔咒の 提交于 2020-01-09 11:12:50
问题 Whatever you want to call it, I'm trying to figure out a way to take the contents of an existing string and evaluate them as a double-quoted string. For example, if I create the following strings: $string = 'The $animal says "meow"' $animal = 'cat' Then, Write-Host $string would produce The $animal says "meow" . How can I have $string re-evaluated, to output (or assign to a new variable) The cat says "meow" ? How annoying...the limitations on comments makes it very difficult (if it's even

MATLAB: Using interpolation to replace missing values (NaN)

会有一股神秘感。 提交于 2020-01-09 10:47:28
问题 I have cell array each containing a sequence of values as a row vector. The sequences contain some missing values represented by NaN . I would like to replace all NaNs using some sort of interpolation method, how can I can do this in MATLAB? I am also open to other suggestions on how to deal with these missing values. Consider this sample data to illustrate the problem: seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) <

MATLAB: Using interpolation to replace missing values (NaN)

隐身守侯 提交于 2020-01-09 10:46:12
问题 I have cell array each containing a sequence of values as a row vector. The sequences contain some missing values represented by NaN . I would like to replace all NaNs using some sort of interpolation method, how can I can do this in MATLAB? I am also open to other suggestions on how to deal with these missing values. Consider this sample data to illustrate the problem: seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) <

interpolate 3D volume with numpy and or scipy

爷,独闯天下 提交于 2020-01-09 09:01:47
问题 I am extremely frustrated because after several hours I can't seem to be able to do a seemingly easy 3D interpolation in python. In Matlab all I had to do was Vi = interp3(x,y,z,V,xi,yi,zi) What is the exact equivalent of this using scipy's ndimage.map_coordinate or other numpy methods? Thanks 回答1: In scipy 0.14 or later, there is a new function scipy.interpolate.RegularGridInterpolator which closely resembles interp3 . The MATLAB command Vi = interp3(x,y,z,V,xi,yi,zi) would translate to

Using approx function on grouped data in R

谁说胖子不能爱 提交于 2020-01-07 06:56:10
问题 I have a big data set with columns Id, Vg, Device, Die, W ,L and others (not relevant to this question). I want to interpolate Vg at a given value of Id but this operation has to be performed on data grouped by column Device and Die. My sample data looks like Die Device Id Vg W L 1 Device1 1 0 10 1 1 Device1 1.2 0.1 10 1 1 Device1 1.3 0.2 10 1 1 Device2 1 0 10 2 1 Device2 1.2 0.1 10 2 1 Device2 1.3 0.2 10 2 1 Device3 1 0 10 3 1 Device3 1.2 0.1 10 3 1 Device3 1.3 0.2 10 3 Each die has 22