我有一个功能作用于3D阵列的每个2D切片.如何对函数进行向量化以避免循环以提高性能?例如:
def interp_2d(x0,y0,z0,x1,y1):
# x0, y0 and z0 are 2D array
# x1 and y1 are 2D array
# peform 2D interpolation
return z1
# now I want to call the interp_2d for each 2D slice of z0_3d as following:
for k in range(z0_3d.shape[2]):
z1_3d[:,:,k]=interp_2d(x0, y0, z0_3d[:,:,k], x1, y1)
Run Code Online (Sandbox Code Playgroud)