哪个是通过列值有效过滤numpy矩阵的正确方法?

问题描述 投票:0回答:1

我正在使用像这样的numpy矩阵:

[[   0    1    2 ...,   97   98  0]
 [ 100  101  102 ...,  197  198  0]
 [ 200  201  202 ...,  297  298  1]
 ...,
 [9700 9701 9702 ..., 9797 9798 1]
 [9800 9801 9802 ..., 9897 9898 0]
 [9900 9901 9902 ..., 9997 9998 0]]

如何删除在numpy矩阵的最后一列中有一行的所有行?:

[[   0    1    2 ...,   97   98  0]
 [ 100  101  102 ...,  197  198  0]
 ...,
 [9800 9801 9802 ..., 9897 9898 0]
 [9900 9901 9902 ..., 9997 9998 0]]

我试图将矩阵转换为pandas数据帧并按最后一列过滤:

matrix = pd.DataFrame(data=second_round_mat[1:,1:])
matrix = matrix[matrix['567'] != 1.0]

但是,这不是很方便,也许在numpy中有类似的方法可以做到这一点,因此如何在numpy中按列值进行过滤?

python python-3.x numpy scipy
1个回答
1
投票

您可以直接在numpy中选择这样的行:

matrix = matrix[matrix[:, -1] != 1]
© www.soinside.com 2019 - 2024. All rights reserved.