【发布时间】:2016-10-09 13:26:13
【问题描述】:
我有 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-learn 分类算法一起使用。因此,我应该如何hstack多个不同的稀疏矩阵?。
【问题讨论】:
标签: python numpy machine-learning scipy scikit-learn