直接切片是不行的:

>>> a=[[1,2,3], [4,5,6]] >>> a[:, 0]                   # 嘗試用數(shù)組的方法讀取一列失敗 TypeError: list indices must be integers or slices, not tuple
  • 1
  • 2
  • 3

我們可以直接構(gòu)造:

>>> b = [i[0] for i in a]     # 從a中的每一行取第一個元素。 >>> print(b) [1, 4]

Reference:

https://blog.csdn.net/xiaotao_1/article/details/80729458