我正在使用 sklearn 进行机器学习工作。这是我的两个变量:
>>> matrix
<1397x9576 sparse matrix of type '<type 'numpy.float64'>'
with 44655 stored elements in Compressed Sparse Row format>
>>> type(density)
<type 'list'>
>>> len(density)
1397
矩阵
由TfidfVectorizer.fit_transform()
生成。我想通过添加变量密度
作为新列来扩展变量矩阵
。有什么方法可以实现它吗?
最佳答案
使用scipy hstack将列密度与矩阵堆叠
from scipy.sparse import hstack
new_matrix = hstack([matrix, density])
关于python - scipy.sparse.csr.csr_matrix :Matrix extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49506843/