bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _construct / hstack
function
scipy.sparse._construct:hstack
source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_construct.py:1129
Signature
def hstack(blocks, format = None, dtype = None)Summary
Stack sparse matrices horizontally (column wise).
Parameters
blocks: sequence of sparse matrices or arrayssequence of sparse matrices with compatible shapes
format: strsparse format of the result (e.g., "csr") by default an appropriate sparse matrix format is returned. This choice is subject to change.
dtype: dtype, optionalThe data-type of the output matrix. If not given, the dtype is determined from that of
blocks.
Returns
new_array: sparse matrix or arrayIf any block in blocks is a sparse array, return a sparse array. Otherwise return a sparse matrix.
If you want a sparse array built from blocks that are not sparse arrays, use
block(hstack(blocks))or convert one block e.g.blocks[0] = csr_array(blocks[0]).
Examples
from scipy.sparse import coo_array, hstack A = coo_array([[1, 2], [3, 4]]) B = coo_array([[5], [6]]) hstack([A,B]).toarray()✓
array([[1, 2, 5],
[3, 4, 6]])
See also
- vstack
stack sparse matrices vertically (row wise)
Aliases
scipy.sparse.hstack