如何从多维数组中提取一列? [英] How do you extract a column from a multi-dimensional array?
本文介绍了如何从多维数组中提取一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在 Python 中从多维数组中提取一列吗?
Does anybody know how to extract a column from a multi-dimensional array in Python?
推荐答案
>>> 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"来分配内存
See also: "numpy.arange" and "reshape" to allocate memory
示例:(分配具有矩阵 (3x4) 整形的数组)
Example: (Allocating a array with shaping of matrix (3x4))
nrows = 3
ncols = 4
my_array = numpy.arange(nrows*ncols, dtype='double')
my_array = my_array.reshape(nrows, ncols)
这篇关于如何从多维数组中提取一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文