从2d numpy数组中提取列

时间:2015-06-29 03:56:25

标签: python numpy

我有2d numpy数组:

import numpy as np

a = np.array([[1,2,3,4],
              [4,5,6,7]])

如何提取以下数组?

result = array([[3,4],
               [6,7]]

1 个答案:

答案 0 :(得分:3)

这称为slicing,您可以使用<array>[<row indexes>,<column indexes>]

示例 -

import numpy as np

a = np.array([[1,2,3,4],
              [4,5,6,7]])

print(a[:,2:])
>>> [[3 4]
     [6 7]]