scipy.sparse.csr.csr_matrix:矩阵扩展 [英] scipy.sparse.csr.csr_matrix:Matrix extension
本文介绍了scipy.sparse.csr.csr_matrix:矩阵扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用sklearn进行机器学习,这是我的两个变量:
I am using sklearn to do machine learning works.Here are my two variables:
>>> 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()
生成.我想通过添加变量 density
作为新列来扩展变量 matrix
.有什么方法可以实现?
matrix
is generated by TfidfVectorizer.fit_transform()
. I want to extend the variable matrix
by adding variable density
as a new column.Is there any way to achieve it?
推荐答案
使用scipy hstack 用矩阵堆叠列密度
Use scipy hstack to stack the column density with matrix
from scipy.sparse import hstack
new_matrix = hstack([matrix, density])
这篇关于scipy.sparse.csr.csr_matrix:矩阵扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文