小编Yon*_*eng的帖子

向量化在ndarray的子​​阵列上操作的函数

我有一个功能作用于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)

python arrays numpy

5
推荐指数
1
解决办法
244
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1