给定一个表示离散坐标转换函数的4D数组,如下:
arr[x_in, y_in, z_in] = [x_out, y_out, z_out]
我想将arr
插值到具有更多元素的网格上(假设arr
中的样本最初是从高元素正方体的等间距网格中抽取的)。
我尝试了scipy中的RegularGridInterpolator
,但速度比较慢:
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from time import time
target_size = 32
reduced_size = 5
small_shape = (reduced_size,reduced_size,reduced_size,3)
cube_small = np.random.randint(target_size, size=small_shape, dtype=np.uint8)
igrid = 3*[np.linspace(0, target_size-1, reduced_size)]
large_shape = (target_size, target_size, target_size,3)
cube_large = np.empty(large_shape)
t0 = time()
interpol = RegularGridInterpolator(igrid, cube_small)
for x in np.arange(target_size):
for y in np.arange(target_size):
for z in np.arange(target_size):
cube_large[x,y,z] = interpol([x,y,z])
print(time()-t0)
有没有什么算法能更适用于这个任务? 或许存在一些方法可以利用在这种情况下,我只对每个点的离散整数值感兴趣的事实。