mat.data.append([val for _, val in doc])
docs = i + 1
mat._shape = (docs, m)
mat = mat.tocsr().transpose() // transpose back to documents=columns
assert isinstance(mat, scipy.sparse.csc_matrix)
return mat
After Change
with documents as columns.
logger.debug("constructing sparse document matrix")
docs, data, indices, indptr = 0, [], [], [0]
for doc in corpus:
indptr.append(len(doc))
indices.extend([feature_id for feature_id, _ in doc])