cupyx.scipy.sparse.hstack#

cupyx.scipy.sparse.hstack(blocks, format=None, dtype=None)[source]#

Stacks sparse matrices horizontally (column wise)

Parameters:
  • blocks (sequence of cupyx.scipy.sparse.spmatrix) – sparse matrices to stack

  • format (str) – sparse format of the result (e.g. “csr”) by default an appropriate sparse matrix format is returned. This choice is subject to change.

  • dtype (dtype, optional) – The data-type of the output matrix. If not given, the dtype is determined from that of blocks.

Returns:

the stacked sparse matrix

Return type:

cupyx.scipy.sparse.spmatrix

Examples

>>> from cupy import array
>>> from cupyx.scipy.sparse import csr_matrix, hstack
>>> A = csr_matrix(array([[1., 2.], [3., 4.]]))
>>> B = csr_matrix(array([[5.], [6.]]))
>>> hstack([A, B]).toarray()
array([[1., 2., 5.],
       [3., 4., 6.]])