简体   繁体   中英

interpolate / downsample 2D array in Python

I have 2 separate arrays with different sizes:

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). I have tried scipy interpolate such as:

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?

I don't think that interp2d actually generates more points for you, it defines an interpolation function over a grid. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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