def _count_nans_per_row_sparse(X, weights):
Count the number of nans (undefined) values per row.
items_per_row = 1 if X.ndim == 1 else X.shape[1]
counts = np.ones(X.shape[0]) * items_per_row
nnz_per_row = np.bincount(X.indices, minlength=len(counts))
counts -= nnz_per_row
if weights is not None:
counts *= weights
return np.sum(counts)
def bincount(X, max_val=None, weights=None, minlength=None):
Return counts of values in array X.
After Change
def _count_nans_per_row_sparse(X, weights):
Count the number of nans (undefined) values per row.
counts = np.fromiter((np.isnan(row.data).sum() for row in X), dtype=np.float)
if weights is not None:
counts *= weights
return counts
def bincount(X, max_val=None, weights=None, minlength=None):
Return counts of values in array X.