我有一个这样的数组:
array([[-0.57098887, -0.4274751 , -0.38459931, -0.58593526],
[-0.22279713, -0.51723555, 0.82462029, 0.05319973],
[ 0.67492385, -0.69294472, -0.2531966 , 0.01403201],
[ 0.41086611, 0.26374238, 0.32859738, -0.80848795]])
现在我想提取以下内容:
[-0.57098887, -0.4274751]
[-0.22279713, -0.51723555]
[ 0.67492385, -0.69294472]
[ 0.41086611, 0.26374238]
所以基本上只有前两列..
发布于 2012-05-17 03:13:40
如果a
是您的数组:
In [11]: a[:,:2]
Out[11]:
array([[-0.57098887, -0.4274751 ],
[-0.22279713, -0.51723555],
[ 0.67492385, -0.69294472],
[ 0.41086611, 0.26374238]])
发布于 2015-05-15 02:20:17
我知道这是一个相当古老的问题-
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
假设您想提取前2行和前3列
A_NEW = A[0:2, 0:3]
A_NEW = [[1, 2, 3],
[4, 5, 6]]
理解语法
A_NEW = A[start_index_row : stop_index_row,
start_index_column : stop_index_column)]
如果需要行2和列2和3
A_NEW = A[1:2, 1:3]
参考numpy索引和切片文章- Indexing & Slicing
https://stackoverflow.com/questions/10625096
复制相似问题