我有一个类似
的numpy数组A.shape
(512,270,1,20)
我不想在维度4中使用所有20个图层。新数组应该像
Anew.shape
(512,270,1,2)
所以我想裁掉数组A的2个“切片”
答案 0 :(得分:6)
来自the python documentation,答案是:
start = 4 # Index where you want to start.
Anew = A[:,:,:,start:start+2]
答案 1 :(得分:3)
您可以使用a list or array of indices而不是切片表示法来选择最终维度中的任意索引序列:
x = np.zeros((512, 270, 1, 20))
y = x[..., [4, 10]] # the 5th and 11th indices in the final dimension
print(y.shape)
# (512,270,1,2)