resampling, interpolating matrix

前端 未结 8 1480
-上瘾入骨i
-上瘾入骨i 2020-12-17 22:02

I\'m trying to interpolate some data for the purpose of plotting. For instance, given N data points, I\'d like to be able to generate a \"smooth\" plot, made up of 10*N or s

8条回答
  •  生来不讨喜
    2020-12-17 22:25

    Here's a minimal example of 1d interpolation with scipy -- not as much fun as reinventing, but.
    The plot looks like sinc, which is no coincidence: try google spline resample "approximate sinc".
    (Presumably less local / more taps ⇒ better approximation, but I have no idea how local UnivariateSplines are.)

    """ interpolate with scipy.interpolate.UnivariateSpline """
    from __future__ import division
    import numpy as np
    from scipy.interpolate import UnivariateSpline
    import pylab as pl
    
    N = 10 
    H = 8
    x = np.arange(N+1)
    xup = np.arange( 0, N, 1/H )
    y = np.zeros(N+1);  y[N//2] = 100
    
    interpolator = UnivariateSpline( x, y, k=3, s=0 )  # s=0 interpolates
    yup = interpolator( xup )
    np.set_printoptions( 1, threshold=100, suppress=True )  # .1f
    print "yup:", yup
    
    pl.plot( x, y, "green",  xup, yup, "blue" )
    pl.show()
    

    Added feb 2010: see also basic-spline-interpolation-in-a-few-lines-of-numpy

提交回复
热议问题