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

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

    check it out!

    a = [[1, 2], [2, 3], [3, 4]]
    a2 = zip(*a)
    a2[0]
    

    it is the same thing as above except somehow it is neater the zip does the work but requires single arrays as arguments, the *a syntax unpacks the multidimensional array into single array arguments

提交回复
热议问题