【602】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]]]])
标签:...,13,21,22,602,Python,array,10 来源: https://www.cnblogs.com/alex-bn-lee/p/15000109.html