bundles / scipy latest / scipy / sparse / _construct / vstack
function
scipy.sparse._construct:vstack
Signature
def vstack ( blocks , format = None , dtype = None ) Summary
Stack sparse arrays vertically (row wise)
Parameters
blockssequence of sparse arrays with compatible shapes
format: str, optionalsparse format of the result (e.g., "csr") by default an appropriate sparse array format is returned. This choice is subject to change.
dtype: dtype, optionalThe data-type of the output array. 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(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()✓
See also
- hstack
stack sparse matrices horizontally (column wise)
Aliases
-
scipy.sparse.vstack