Search code examples
pythonscipysparse-matrix

How do we hstack many csr matrices programatically?


https://docs.scipy.org/doc/scipy/reference/reference/generated/scipy.sparse.hstack.html#scipy.sparse.hstack

I am vectorizing around 12 text features individually using glove vectors I am having these 12 csr matrices in a list l

is there a way to stack them all without manually passing each one to hstack function

np.hstack(l[0],l[1],.....,l[11])

please suggest alternative to this


Solution

  • Your link is to the sparse.hstack. That takes a sequence, a list, of sparse matrices. That's what your l is.

     newmat = sparse.hstack(l)
    

    The np stack functions also take a list, but shouldn't be used here,