def _document_frequency(X):
 if sp.isspmatrix_csr(X):
  return bincount(X.indices, minlength=X.shape[1])
 else:
  return np.diff(sp.csc_matrix(X, copy=False).indptr)

def _document_frequency ( X ) : if sp . isspmatrix_csr ( X ) : return bincount ( X . indices , minlength = X . shape [ 1 ] ) else : return np . diff ( sp . csc_matrix ( X , copy = False ) . indptr )
count the number of non-zero values for each feature in sparse x .