rougier/numpy-100

The solution to Q60 is not clear

lots-o opened this issue · 2 comments

The task is as follows:

How to tell if a given 2D array has null columns?

The solution is as follows :

Z = np.random.randint(0,3,(3,10))
print((~Z.any(axis=0)).any())

I think If meaning of the null is 0, the solution is correct. But if it is np.nan, the solution is incorrect.

An alternative solution will be :

# null : 0 
Z = np.random.randint(0,3,(3,10))
print((~Z.any(axis=0)).any())

# null : np.nan
Z=np.array([
    [0,1,np.nan],
    [1,2,np.nan],
    [4,5,np.nan]
])
print(np.isnan(Z).all(axis=0))

Thanks. The meaning of null is actually 0 but your addition might be worth a read. Can you make a PR ?

Yes i can.