from numpy import *
if __name__ == '__main__':
a = [[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]]
for x in a:
print(x[0])
b = array(a)
print(b[:,0])
1
3
1
23
[ 1 3 1 23]
如果对列表直接访问
a = [[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]]
print(a[:,0])
会出现如下错误
TypeError: list indices must be integers or slices, not tuple