如果该行的元素之一不满足条件,该如何删除数组的行? [英] How could I remove the rows of an array if one of the elements of the row does not satisfy a condition?
本文介绍了如果该行的元素之一不满足条件,该如何删除数组的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当数组第三列的元素少于特定数量时,我想删除数组的行.例如:
I would like to remove the rows of an array when the elements of third column of the array are less than specific amount. For example:
a=np.array([[2331.13,1944.88,23.1379,7,3.18339,0.482105],
[8168.44,1904.70,19.5025,265,4.12642,0.0376510],
[7389.36,1983.97,14.3581,3937,6.04109,0.713416],
[1765.18,1944.29,22.5495,35,2.30717,0.794432],
[2319.33,1946.68,22.4300,25,3.63676,0.0210690],
[785.666,2090.69,14.7940,1095,2.52823,0.999842],
[4071.24,2186.92,22.6616,31,2.79309,0.0312501],
[7082.51,2191.69,23.0122,19,2.53166,0.687001]])
我要删除满足以下条件的行:
I would like to remove rows which satisfy the following condition:
a[:,2]<15.0
干杯.
推荐答案
您可以这样做:
a[a[:,2]>=15.0, :]
请注意将a[:,2]<15.0
转换为a[:,2]>=15.0
,以便在此描述要保留而不是删除的行.
Note the inversion of a[:,2]<15.0
to a[:,2]>=15.0
, so that you're describing rows that you want to keep rather than remove.
如果要逆转条件并非如此简单,则还可以使用~
:
If inverting your condition isn't as simple as that, you could also use ~
:
a[~(a[:,2]<15.0), :]
这篇关于如果该行的元素之一不满足条件,该如何删除数组的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文