0

I have two numpy arrays, one of a boolean type, the other float type. I want to get the rows of XY_coord where one of the colums has a row with True (so all rows in XY_coord with False-False in BOOL are removed. How do I do this?

BOOL = np.array([[False,  True],
           [False,  True],
           [False,  True],
           [False,  True],
           [ True,  True],
           [ True, False],
           [False, False],
           [False, False],
           [ True, False]])
       
XY_coord =    np.array([[-192.9594843 ,   78.17485294],
           [-182.2699483 ,   50.143909  ],
           [-171.5804122 ,   22.11296505],
           [ -51.11635646,  132.2664039 ],
           [ -40.42682039,  104.2354599 ],
           [ -29.73728432,   76.20451597],
           [  90.72677139,  186.3579548 ],
           [ 101.4163075 ,  158.3270108 ],
           [ 112.1058435 ,  130.2960669 ]])

I can do:

XY_coord[out[:,0]]
XY_coord[out[:,1]]

and append the outcome, but my matrix is much larger, so this will be inefficient.

2 Answers 2

1

There are many ways to solve this. Since you only care about dropping rows with False, False I would convert the BOOL array to a row index: keep_row = BOOL.sum(axis=1).astype('bool'). Then you can simply take XY_coord[keep_row] to get your filtered array.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this-

XY_coord[BOOL[:,0] | BOOL[:,1], :]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.