def __init__(self, sparse, id_order=None): if not scipy.sparse.issparse(sparse): raise ValueError("must pass a scipy sparse object") rows, cols = sparse.shape if rows != cols: raise ValueError("Weights object must be square") self.sparse = sparse.tocsr() self.n = sparse.shape[0] if id_order: if len(id_order) != self.n: raise ValueError("Number of values in id_order must match shape of sparse") self.id_order = id_order self._cache = {}
def __init__(self, sparse, documents_columns=True): """ Parameters ---------- sparse : `scipy.sparse` Corpus scipy sparse format documents_columns : bool, optional If True - documents will be column, rows otherwise. """ if documents_columns: self.sparse = sparse.tocsc() else: self.sparse = sparse.tocsr().T # make sure shape[1]=number of docs (needed in len())
def __init__(self, sparse, documents_columns=True): if documents_columns: self.sparse = sparse.tocsc() else: self.sparse = sparse.tocsr().T # make sure shape[1]=number of docs (needed in len())
def __init__(self, sparse, documents_columns=True): if documents_columns: self.sparse = sparse.tocsc() else: self.sparse = sparse.tocsr( ).T # make sure shape[1]=number of docs (needed in len())