提取一个numpy矩阵的前n列 [英] Extracting first n columns of a numpy matrix
本文介绍了提取一个numpy矩阵的前n列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的数组:
I have an array like this:
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]])
现在我要提取以下内容:
Now I want to extract the following:
[-0.57098887, -0.4274751]
[-0.22279713, -0.51723555]
[ 0.67492385, -0.69294472]
[ 0.41086611, 0.26374238]
所以基本上只是前两列.
So basically just first 2 columns..
推荐答案
如果a
是您的数组:
In [11]: a[:,:2]
Out[11]:
array([[-0.57098887, -0.4274751 ],
[-0.22279713, -0.51723555],
[ 0.67492385, -0.69294472],
[ 0.41086611, 0.26374238]])
这篇关于提取一个numpy矩阵的前n列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文