scipy.sparse.
block_array#
- scipy.sparse.block_array(blocks, *, format=None, dtype=None)[source]#
Build a sparse array from sparse sub-blocks
- Parameters:
- blocksarray_like
Grid of sparse arrays with compatible shapes. An entry of None implies an all-zero array.
- format{‘bsr’, ‘coo’, ‘csc’, ‘csr’, ‘dia’, ‘dok’, ‘lil’}, optional
The sparse format of the result (e.g. “csr”). By default an appropriate sparse array format is returned. This choice is subject to change.
- dtypedtype, optional
The data-type of the output array. If not given, the dtype is determined from that of blocks.
- Returns:
- blocksparse array
See also
block_diag
specify blocks along the main diagonals
diags
specify (possibly offset) diagonals
Examples
>>> from scipy.sparse import coo_array, block_array >>> A = coo_array([[1, 2], [3, 4]]) >>> B = coo_array([[5], [6]]) >>> C = coo_array([[7]]) >>> block_array([[A, B], [None, C]]).toarray() array([[1, 2, 5], [3, 4, 6], [0, 0, 7]])
>>> block_array([[A, None], [None, C]]).toarray() array([[1, 2, 0], [3, 4, 0], [0, 0, 7]])