【发布时间】:2021-07-19 08:56:46
【问题描述】:
我有一个 3D 体积,我沿着不同的轴修改切片。
for idx in range(len(self.volume)):
for axe in range(self.volume.ndim): # = range(3)
slice_ = np.take(self.volume, idx, axis = axe)
''' Do something '''
(np.take 相当于写 self.volume[idx], self.volume[:, idx] 和 self.volume[:, :, idx])
最后,我想在我的卷中沿轴分配一个新切片:
if axe == 0:
self.volume[idx] = new_slice
elif axe == 1:
self.volume[:,idx] = new_slice
else:
self.volume[:,:,idx] = new_slice
这是我需要帮助的地方。我想不出一种更清洁的方式来完成这项任务。 (我想要像 np.take() 这样干净的东西)
我已经尝试过 np.insert、np.insert_along_axis、np.put、np.put_along_axis...但我显然遗漏了一些东西。
有什么想法吗? :)
祝你有美好的一天
【问题讨论】:
标签: python numpy numpy-ndarray