Add more sample points to data

Chr*_*oph 6 python numpy scipy

Given some data of shape 20x45, where each row is a separate data set, say 20 different sine curves with 45 data points each, how would I go about getting the same data, but with shape 20x100?

In other words, I have some data A of shape 20x45, and some data B of length 20x100, and I would like to have A be of shape 20x100 so I can compare them better.

This is for Python and Numpy/Scipy.

我假设它可以用样条线完成,所以我正在寻找一个简单的例子,可能只是2x10到2x20或其他东西,其中每一行只是一行,以演示解决方案.

谢谢!

Joe*_*ton 7

在我输入这个例子的时候,Ubuntu打败了我,但是他的例子只是使用线性插值,使用numpy.interpolate可以更容易地完成...(但是差异只是scipy.interpolate.interp1d中的关键字参数) .

我想我会包含我的例子,因为它显示使用带有三次样条的scipy.interpolate.interp1d ...

import numpy as np
import scipy as sp
import scipy.interpolate
import matplotlib.pyplot as plt

# Generate some random data
y = (np.random.random(10) - 0.5).cumsum()
x = np.arange(y.size)

# Interpolate the data using a cubic spline to "new_length" samples
new_length = 50
new_x = np.linspace(x.min(), x.max(), new_length)
new_y = sp.interpolate.interp1d(x, y, kind='cubic')(new_x)

# Plot the results
plt.figure()
plt.subplot(2,1,1)
plt.plot(x, y, 'bo-')
plt.title('Using 1D Cubic Spline Interpolation')

plt.subplot(2,1,2)
plt.plot(new_x, new_y, 'ro-')

plt.show()
Run Code Online (Sandbox Code Playgroud)

替代文字