a[...,:2]表示只留下a这个list最后那个维度中的前两个数即a[...,0]和a[...,1]

例如:

import tensorflow as tf
import numpy as np

if __name__ == '__main__':
    a = np.array([[[1, 2, 21], [3, 4, 34]], [[5, 6, 56], [7, 8, 78]]])
    print('a.shape:', a.shape)
    b = a[..., :2]
    print('b :', b)
    print('shape.b:', b.shape)

结果:

a.shape: (2, 2, 3)
b : [[[1 2]
  [3 4]]

 [[5 6]
  [7 8]]]
shape.b: (2, 2, 2)

如果是

  b = a[..., :1]

结果:

a.shape: (2, 2, 3)
b : [[[1]
  [3]]

 [[5]
  [7]]]
shape.b: (2, 2, 1)