a = a[~(np.isnan(a).any(axis=0))] # removes columns containing at least one nan a = a[~(np.isnan(a).all(axis=0))] # removes columns containing all nan