从numpy数组中选择特定的行组

时间:2017-09-24 04:14:47

标签: python numpy

我有一个特定大小的numpy矩阵(作为一个例子,假设我们有一个矩阵' A ',它有5行10列)。我想从这个numpy矩阵中选择几列(假设我想选择行2,3,4,7,9)并创建另一个矩阵(B)。

例如,

import numpy as np
A = np.random.randint(5, size=(5, 10))
print A

[[1 3 2 1 2 1 0 2 2 2]
 [2 2 4 4 1 3 4 1 4 4]
 [2 4 1 3 0 4 3 0 1 0]
 [4 4 1 3 0 4 4 1 3 1]
 [1 0 1 2 1 0 4 0 1 3]]

得到的矩阵B应为:

B = [[2 1 2 2 2]
     [4 4 1 1 4]
     [1 3 0 0 0]
     [1 3 0 1 1]
     [1 2 1 0 3]]

最好的方法是什么?

0 个答案:

没有答案
相关问题