imichaeldotorg
imichaeldotorg

Reputation: 469

How can I remove rows from a numpy array that have NaN as the first element?

I have a numpy array that looks like this:

 [[nan 0 0 ..., 0.0 0.053526738 0.068421053]
 [nan 0 0 ..., 0.0 0.059653990999999996 0.068421053]
 [nan 0 0 ..., 1.0 0.912542592 0.068421053]
 ..., 
 [1 0 0 ..., 0.0 0.126523399 0.193548387]
 [nan 0 0 ..., 0.0 0.034388807 0.068421053]
 [4 0 0 ..., 0.0 0.02250561 0.068421053]]

How do I remove all rows from the array where nan is the first element?

Upvotes: 1

Views: 1489

Answers (1)

sascha
sascha

Reputation: 33542

If x is the original array, the following puts the valid rows into y:

y = x[~np.isnan(x[:, 0])]

Upvotes: 3

Related Questions