提取numpy数组Python中列的特定RANGE [英] Extract Specific RANGE of columns in numpy array Python

查看:213
本文介绍了提取numpy数组Python中列的特定RANGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组:

e = np.array([[ 0,  1,  2,  3, 5, 6, 7, 8],
              [ 4,  5,  6,  7, 5, 3, 2, 5],
              [ 8,  9, 10, 11, 4, 5, 3, 5]])

我想按RANGE中的列提取数组,如果我想将范围1到5的列都提取,它将返回

I want to extract array by its columns in RANGE, if I want to take column in range 1 until 5, It will return

e = np.array([[ 1,  2,  3, 5, ],
              [ 5,  6,  7, 5, ],
              [ 9, 10, 11, 4, ]])

如何解决?谢谢

推荐答案

您可以只使用e [:, 1:5]检索想要的内容.

You can just use e[:, 1:5] to retrive what you want.

In [1]: import numpy as np

In [2]: e = np.array([[ 0,  1,  2,  3, 5, 6, 7, 8],
   ...:               [ 4,  5,  6,  7, 5, 3, 2, 5],
   ...:               [ 8,  9, 10, 11, 4, 5, 3, 5]])

In [3]: e[:, 1:5]
Out[3]:
array([[ 1,  2,  3,  5],
       [ 5,  6,  7,  5],
       [ 9, 10, 11,  4]])

https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

这篇关于提取numpy数组Python中列的特定RANGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆