从文档,在我看来,你从scipy.sparse
模块寻找hstack
/vstack
:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.sparse as ssp
>>> print ssp.hstack.__doc__
Stack sparse matrices horizontally (column wise)
Parameters
----------
blocks
sequence of sparse matrices with compatible shapes
format : string
sparse format of the result (e.g. "csr")
by default an appropriate sparse matrix format is returned.
This choice is subject to change.
See Also
--------
vstack : stack sparse matrices vertically (row wise)
Examples
--------
>>> from scipy.sparse import coo_matrix, vstack
>>> A = coo_matrix([[1,2],[3,4]])
>>> B = coo_matrix([[5],[6]])
>>> hstack([A,B]).todense()
matrix([[1, 2, 5],
[3, 4, 6]])
>>>
虽然文件在这里说,'block'应该是“稀疏矩阵的序列”,它似乎传递混合'numpy.array'和'scipy.sparse'很好。唯一的副作用是输出矩阵格式可能不是预期的类型,应指定'format'来强制格式转换。 – zaxliu