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

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




欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326918.html