I have a 2d numpy array that contains some numbers like:
data =
[[1.1, 1.2, 1.3, 1.4],
[2.1, 2.2, 2.3, -1.0],
[-1.0, 3.2, 3.3, -1.0],
[-1.0, -1.0. -1.0, -1.0]]
I want to remove every row that contains the value -1.0 2 or more times, so I'm left with
data =
[[1.1, 1.2, 1.3, 1.4],
[2.1, 2.2, 2.3, -1.0]]
I found this question which looks like it's very close to what I'm trying to do, but I can't quite figure out how I can rewrite that to fit my use case.
-1values. Then create an array of True and False values indicating whether each row satisfies the condition. Then mask the original array with the boolean array to remove the rows. And to help you get started, here's how you can do the first two steps...(data == -1).sum(axis=1) >= 2