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

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

    Despite using zip(*iterable) to transpose a nested list, you can also use the following if the nested lists vary in length:

    map(None, *[(1,2,3,), (4,5,), (6,)])
    

    results in:

    [(1, 4, 6), (2, 5, None), (3, None, None)]
    

    The first column is thus:

    map(None, *[(1,2,3,), (4,5,), (6,)])[0]
    #>(1, 4, 6)
    

提交回复
热议问题