数组与列表访问某一列的方法不同

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




posted @ 2018-02-06 15:04  crr121  阅读(174)  评论(0编辑  收藏  举报