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

前端 未结 20 2891
感情败类
感情败类 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:44

    If you have an array like

    a = [[1, 2], [2, 3], [3, 4]]
    

    Then you extract the first column like that:

    [row[0] for row in a]
    

    So the result looks like this:

    [1, 2, 3]
    

提交回复
热议问题