Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing a row that contains a negative float in a numpy aray

I have a numpy array consisting of 3 columns and there is one value in a column that has a negative value. I need to remove the whole row that contains this value as it corresponds to an anomalous result.

The numpy array looks a little like this:

[[98.4, 0.236, 0.0925]

 [95.2, -0.162, 0.0625]

 [92.3, 0.112, 0.0526]]

How would I go about removing the whole row that contains the negative value?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can index with a boolean mask:

result = array[(array >= 0).all(axis=1)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading