我有一个3d数组和一个3d索引列表。我的目标是为每个索引(索引位于卷的中间)分离一个特定大小的小三维卷(3x3x3或5x5x5或其他)。
目前,我这样做:
1)将5个2d数组分组(感兴趣的数组在中间,索引在后面)。所以有一个5xnxn阵列。
2)对于5x5x5卷,对于我的5xnxn阵列的每个2d阵列(0、n、n;1、n、n…等),我将围绕同一索引裁剪一个5x5阵列。
3)将这五个5x5二维阵列叠加,以获得我的小三维体积。
有没有最快的方法来做这项工作?
这里有一个解释代码:
arr = np.zeros((7,7,7)) #Just a 3D array
ind = [3, 3, 3] #My index
for el in range(arr.shape[0]):
if el==ind[0]:
group = arr[el-2:el+3] #it isolates a 3D volume with arr[ind[0]] in the middle
volume_3d = []
for i in group:
volume_2d = i[ind[1]-2:ind[1]+3, ind[2]-2:ind[2]+3]
volume_3d.append (volume_2d) #it builds the 3D volume
谢谢