提取一个numpy矩阵的前n列
我有一个像这样的数组:
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]
所以基本上只是前两列。
回答:
如果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列 的全部内容, 来源链接: utcz.com/qa/419672.html