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

新手上路,请多包涵

有谁知道如何从 Python 中的多维数组中提取列?

原文由 jaweria 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 335
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)

原文由 Andre Luiz 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题