我有2d numpy数组:
import numpy as np
a = np.array([[1,2,3,4],
[4,5,6,7]])
如何提取以下数组?
result = array([[3,4],
[6,7]]
答案 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]]