How do you extract a column from a multi-dimensional array?

前端 未结 20 2840
感情败类
感情败类 2020-12-02 03:56

Does anybody know how to extract a column from a multi-dimensional array in Python?

20条回答
  •  醉梦人生
    2020-12-02 04:25

    def get_col(arr, col):
        return map(lambda x : x[col], arr)
    
    a = [[1,2,3,4], [5,6,7,8], [9,10,11,12],[13,14,15,16]]
    
    print get_col(a, 3)
    

    map function in Python is another way to go.

提交回复
热议问题