Concatenate sparse matrices in Python using SciPy/Numpy

后端 未结 1 1301
囚心锁ツ
囚心锁ツ 2020-12-01 03:51

What would be the most efficient way to concatenate sparse matrices in Python using SciPy/Numpy?

Here I used the following:

>>> np.hstack((X         


        
1条回答
  •  再見小時候
    2020-12-01 04:04

    You can use the scipy.sparse.hstack to concatenate sparse matrices with the same number of rows (horizontal concatenation):

    from scipy.sparse import hstack
    hstack((X, X2))
    

    Similarly, you can use scipy.sparse.vstack to concatenate sparse matrices with the same number of columns (vertical concatenation).

    Using numpy.hstack or numpy.vstack will create an array with two sparse matrix objects.

    0 讨论(0)
提交回复
热议问题