This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _construct / vstack

function

scipy.sparse._construct:vstack

source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_construct.py:1176

Signature

def vstack(blocks, format = None, dtype = None)

Summary

Stack sparse arrays vertically (row wise).

Parameters

blocks : sequence of sparse matrices or arrays

sequence of sparse arrays with compatible shapes

format : str, optional

sparse format of the result (e.g., "csr") by default an appropriate sparse array format is returned. This choice is subject to change.

dtype : dtype, optional

The data-type of the output array. If not given, the dtype is determined from that of blocks.

Returns

new_array : sparse matrix or array

If 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(vstack(blocks)) or convert one block e.g. blocks[0] = csr_array(blocks[0]).

Examples

from scipy.sparse import coo_array, vstack
A = coo_array([[1, 2], [3, 4]])
B = coo_array([[5, 6]])
vstack([A, B]).toarray()
✓
array([[1, 2],
       [3, 4],
       [5, 6]])

See also

hstack

stack sparse matrices horizontally (column wise)

Aliases

  • scipy.sparse.vstack

Referenced by