开发者社区 问答 正文

如何从多维数组中提取列?

有人知道如何在Python中从多维数组中提取列吗?

展开
收起
保持可爱mmm 2020-01-16 16:07:20 404 分享 版权
1 条回答
写回答
取消 提交回答
  • import numpy as np A = np.array([[1,2,3,4],[5,6,7,8]])

    A array([[1, 2, 3, 4], [5, 6, 7, 8]])

    A[:,2] # returns the third columm array([3, 7]) 另请参阅:“ numpy.arange”和“ reshape”以分配内存

    示例:(使用矩阵整形(3x4)分配数组)

    nrows = 3 ncols = 4 my_array = numpy.arange(nrows*ncols, dtype='double') my_array = my_array.reshape(nrows, ncols) 问题来源于stack overflow

    2020-01-16 16:07:37
    赞同 展开评论
问答分类:
问答地址: