removing pairs of elements from numpy arrays that are NaN (or another value) in Python
- by user248237
I have an array with two columns in numpy. For example:
a = array([[1, 5, nan, 6],
[10, 6, 6, nan]])
a = transpose(a)
I want to efficiently iterate through the two columns, a[:, 0] and a[:, 1] and remove any pairs that meet a certain condition, in this case if they are NaN. The obvious way I can think of is:
new_a = []
for val1, val2 in a:
if val2 == nan or val2 == nan:
new_a.append([val1, val2])
But that seems clunky. What's the pythonic numpy way of doing this?
thanks.