cupyx.scipy.sparse.bmat#
- cupyx.scipy.sparse.bmat(blocks, format=None, dtype=None)[source]#
Builds a sparse array/matrix from sparse sub-blocks
- Parameters:
blocks (array_like) – Grid of sparse objects with compatible shapes. An entry of None implies an all-zero block.
format ({'coo', 'csc', 'csr', 'dia'}, optional) – The sparse format of the result (e.g. “csr”). By default an appropriate sparse format is returned. This choice is subject to change.
dtype (dtype, optional) – The data-type of the output. If not given, the dtype is determined from that of blocks.
- Returns:
The assembled sparse object. Returns a sparse array when any block is a sparse array, else a sparse matrix (matches scipy).
- Return type:
cupyx.scipy.sparse
See also
Examples
>>> from cupy import array >>> from cupyx.scipy.sparse import csr_matrix, bmat >>> A = csr_matrix(array([[1., 2.], [3., 4.]])) >>> B = csr_matrix(array([[5.], [6.]])) >>> C = csr_matrix(array([[7.]])) >>> bmat([[A, B], [None, C]]).toarray() array([[1., 2., 5.], [3., 4., 6.], [0., 0., 7.]]) >>> bmat([[A, None], [None, C]]).toarray() array([[1., 2., 0.], [3., 4., 0.], [0., 0., 7.]])