假设我有一个形状为(1, n)
的some_data
数据。我有一个新的形状为(1, n±x)
的incoming_data
数据,其中x是比n
小得多的正整数。我想将incoming_data
压缩或拉伸,使其与n
具有相同的长度。使用SciPy堆栈,应该如何完成这个操作呢?
这里是我试图实现的一个例子。
# Stretch arr2 to arr1's shape while "filling in" interpolated value
arr1 = np.array([1, 5, 2, 3, 7, 2, 1])
arr2 = np.array([1, 5, 2, 3, 7, 1])
result
> np.array([1, 5, 2, 3, 6.x, 2.x 1]) # of shape (arr1.shape)
作为另一个例子:
# Squeeze arr2 to arr1's shape while placing interpolated value.
arr1 = np.array([1, 5, 2, 3, 7, 2, 1])
arr2 = np.array([1, 5, 2, 3, 4, 7, 2, 1])
result
> np.array([1, 5, 2, 3.x, 7.x, 2.x, 1]) # of shape (arr1.shape)
scipy.interpolate
,但是我认为我错过了一些东西,无法正确完成插值,因为我不断收到错误消息,指出数组长度不同。 - ericmjlinterpolate
,将x=np.arange(arr2.size)
和arr2
作为基础点,插值到由np.linspace(0,arr2.size-1,arr1.size)
给出的新x
值。这些元素应该是您插值得到的数值。 - Andras Deak -- Слава Україніhelp(scipy.interpolate.interp1d)
或在线文档。 - Andras Deak -- Слава Україніarr1
),我想将所有内容插值为参考长度。 - ericmjl