参考:python中三个点(…)
三个点表示 numpy 数组中的省略冒号,就是全部包括的省略
例如 a[:, :, :, :-1] 等价于 a[..., :-1]
对于多维度数组的操作会略显方便
>>> import numpy as np >>> a = np.arange(24).reshape(2, 2, 2, 3) >>> a array([[[[ 0, 1, 2], [ 3, 4, 5]], [[ 6, 7, 8], [ 9, 10, 11]]], [[[12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23]]]]) >>> a[...,:-1] array([[[[ 0, 1], [ 3, 4]], [[ 6, 7], [ 9, 10]]], [[[12, 13], [15, 16]], [[18, 19], [21, 22]]]]) >>> a[:,:,:,:-1] array([[[[ 0, 1], [ 3, 4]], [[ 6, 7], [ 9, 10]]], [[[12, 13], [15, 16]], [[18, 19], [21, 22]]]])