I have a numpy 5D array and want to delete the first element and push a new element to the end of the index. Here goes the definition;
我有一个numpy 5D数组,想要删除第一个元素并将一个新元素推送到索引的末尾。这是定义;
images = np.zeros([1,30,image_height,image_width,image_channel])
This is the one to be deleted: images[0,0,:,:,:]
这是要删除的:图像[0,0,:,:,]
And this is the one to be updated: images[0,29,:,:,:]
这是要更新的:图像[0,29,:,:,]
How to delete and add an element from N-D sized array?
如何从N-D大小的数组中删除和添加元素?
Thanks,
1 个解决方案
#1
1
OK, I found it out.
好的,我发现了。
images[0, 0:28, :, :, :] = images[0, 1:29, :, :, :]
images[0, 30, :, :, :] = new_data
To avoid hardcoding indices it can be written as:
为避免硬编码索引,可将其写为:
images[0,0:-1,...] = images[0,1:,...]
images[0,-1,...] = new_data
#1
1
OK, I found it out.
好的,我发现了。
images[0, 0:28, :, :, :] = images[0, 1:29, :, :, :]
images[0, 30, :, :, :] = new_data
To avoid hardcoding indices it can be written as:
为避免硬编码索引,可将其写为:
images[0,0:-1,...] = images[0,1:,...]
images[0,-1,...] = new_data