def n_nonzero_columns(X):
 return len(np.unique(X.nonzero()[1]))

def n_nonzero_columns ( X ) : return len ( np . unique ( X . nonzero ( ) [ 1 ] ) )
returns the number of non-zero columns in a csr matrix x .