我有一个数组:
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之间取列,它将返回
e = np.array([[ 1, 2, 3, 5, ], [ 5, 6, 7, 5, ], [ 9, 10, 11, 4, ]])
怎么解决?谢谢
您可以使用e [:,1:5]来检索您想要的内容.
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