You get rid of items that are NaN, not lines with NaN. Most correct would be:
mask = ~np.any(np.isnan(x), axis=1) x = x[mask] y = y[mask]
To see the different behavior of both approaches:
>>> x = np.random.rand(4, 5) >>> x[[0, 2], [1, 4]] = np.nan >>> x array([[ 0.37499461, nan, 0.51254549, 0.5253203 , 0.3955948 ], [ 0.73817831, 0.70381481, 0.45222295, 0.68540433, 0.76113544], [ 0.1651173 , 0.41594257, 0.66327842, 0.86836192, nan], [ 0.70538764, 0.31702821, 0.04876226, 0.53867849, 0.58784935]]) >>> x[~np.isnan(x)] # 1D array with NaNs removed array([ 0.37499461, 0.51254549, 0.5253203 , 0.3955948 , 0.73817831, 0.70381481, 0.45222295, 0.68540433, 0.76113544, 0.1651173 , 0.41594257, 0.66327842, 0.86836192, 0.70538764, 0.31702821, 0.04876226, 0.53867849, 0.58784935]) >>> x[~np.any(np.isnan(x), axis=1)] # 2D array with rows with NaN removed array([[ 0.73817831, 0.70381481, 0.45222295, 0.68540433, 0.76113544], [ 0.70538764, 0.31702821, 0.04876226, 0.53867849, 0.58784935]]