简体   繁体   English

二维数组的插值

[英]Interpolation for a 2D array

I was wondering if there is a way to interpolate a 2D array in python using the same principle used to interpolate a 1D array ( {np.interpolate} ). 我想知道是否有一种方法可以使用与插补1D数组({np.interpolate})相同的原理在python中插补2D数组。

So my aim is to increase the number of data points that is within my array ([1000,20] to [1000, 200] [Time_indexing, X]). 因此,我的目标是增加数组中的数据点数量([1000,20]到[1000,200] [Time_indexing,X])。

I am looking for a function that is capable of doing that. 我正在寻找能够做到这一点的功能。

A = np.array([[ 0.45717218,  0.44250104,  0.47812272,  0.49092173,  0.46002069],
   [ 0.29829681,  0.26408021,  0.3709202 ,  0.44823109,  0.49311853],
   [ 0.05469835,  0.01048596,  0.17398291,  0.30088943,  0.39783137],
   [-0.20463768, -0.24610673, -0.0713164 ,  0.08406331,  0.22047102],
   [-0.4074527 , -0.43573695, -0.31062521, -0.15750053, -0.00222392]])

This is a [5,5] array i want to interpolate it using a spacing of 0.01 hence the final product should be [500,500]. 这是一个[5,5]数组,我想使用0.01的间距对其进行插值,因此最终乘积应为[500,500]。

Thank you, 谢谢,

You could use interp2d : 您可以使用interp2d

from scipy.interpolate import interp2d
f = interp2d(np.arange(0,500,100), np.arange(0,500,100), A)
f(np.arange(500), np.arange(500))

Output: 输出:

array([[ 0.45717218,  0.45702547,  0.45687876, ...,  0.46002069,
         0.46002069,  0.46002069],
       [ 0.45558343,  0.45543476,  0.45528609, ...,  0.46035167,
         0.46035167,  0.46035167],
       [ 0.45399467,  0.45384405,  0.45369343, ...,  0.46068265,
         0.46068265,  0.46068265],
       ...,
       [-0.4074527 , -0.40773554, -0.40801839, ..., -0.00222392,
        -0.00222392, -0.00222392],
       [-0.4074527 , -0.40773554, -0.40801839, ..., -0.00222392,
        -0.00222392, -0.00222392],
       [-0.4074527 , -0.40773554, -0.40801839, ..., -0.00222392,
        -0.00222392, -0.00222392]])

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

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