How could I remove the rows of an array if one of the elements of the row does not satisfy a condition?

后端 未结 2 1026
一个人的身影
一个人的身影 2020-12-20 06:33

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,1         


        
2条回答
  •  庸人自扰
    2020-12-20 07:04

    You can do:

    a[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), :]
    

提交回复
热议问题