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

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

    You can use this as well:

    values = np.array([[1,2,3],[4,5,6]])
    values[...,0] # first column
    #[1,4]
    

    Note: This is not working for built-in array and not aligned (e.g. np.array([[1,2,3],[4,5,6,7]]) )

提交回复
热议问题