简体   繁体   English

在 Python 中插值/下采样二维数组

[英]interpolate / downsample 2D array in Python

I have 2 separate arrays with different sizes:我有 2 个不同尺寸的独立 arrays:

len(range_data) = 4320
len(az1) = 385
len(az2) = 347

data1.shape = (385,4320)
data2.shape = (347,4320)

I would like for the dimensions of data2 to equal that of data1, such that data2.shape should be (385,4320).我希望data2的尺寸等于data1的尺寸,这样data2.shape应该是(385,4320)。 I have tried scipy interpolate such as:我尝试过 scipy 插值,例如:

f = interpolate.interp2d(az1,range_data,data1,kind='cubic')
znew = f(az2,range_data)

print(znew.shape)
(347,4320)

znew.shape should be (385,4320), any ideas why this is happening and/or what might need to be done to fix this? znew.shape 应该是(385,4320),任何想法为什么会发生这种情况和/或可能需要做些什么来解决这个问题?

I don't think that interp2d actually generates more points for you, it defines an interpolation function over a grid.我不认为interp2d实际上会为您生成更多点,它在网格上定义了插值 function。 That means that what you've created is a way to interpolate points within the grid defined by your first set of data points.这意味着您创建的是一种在由您的第一组数据点定义的网格内插入点的方法。 znew will return an interpolated grid with the same number of values as the x and y passed to it. znew将返回一个插值网格,其值与传递给它的xy相同。

See the source code .请参阅源代码

Returns
        -------
        z : 2-D array with shape (len(y), len(x))
            The interpolated values.

If you want to add extra data points, I would suggest deriving a regression function (or whatever ML technique you want, NNs if you're so inclined) on the second data set and use that function to produce the extra 38 datapoints you need.如果您想添加额外的数据点,我建议您在第二个数据集上推导出回归 function(或任何您想要的 ML 技术,如果您愿意,可以使用 NN)并使用该 function 来生成您需要的额外 38 个数据点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM