2
我有3个稀疏矩阵:如何叠加几个稀疏矩阵(特征矩阵)?
In [39]:
mat1
Out[39]:
(1, 878049)
<1x878049 sparse matrix of type '<type 'numpy.int64'>'
with 878048 stored elements in Compressed Sparse Row format>
In [37]:
mat2
Out[37]:
(1, 878049)
<1x878049 sparse matrix of type '<type 'numpy.int64'>'
with 744315 stored elements in Compressed Sparse Row format>
In [35]:
mat3
Out[35]:
(1, 878049)
<1x878049 sparse matrix of type '<type 'numpy.int64'>'
with 788618 stored elements in Compressed Sparse Row format>
从documentation,我读到有可能hstack
,vstack
,和它们concatenate
这种类型的矩阵。于是,我就hstack
他们:
import numpy as np
matrix1 = np.hstack([[address_feature, dayweek_feature]]).T
matrix2 = np.vstack([[matrix1, pddis_feature]]).T
X = matrix2
然而,尺寸不匹配:
In [41]:
X_combined_features.shape
Out[41]:
(2, 1)
请注意,我堆叠这样的矩阵,因为我想用scikit学习的分类算法使用它们。因此,我应该如何hstack
一些不同的稀疏矩阵?。
感谢您的帮助,很好的回答! –