scipy.sparse.kron#

scipy.sparse.kron(A, B, format=None)[source]#

kronecker product of sparse matrices A and B

Parameters:
Asparse or dense matrix

first matrix of the product

Bsparse or dense matrix

second matrix of the product

formatstr, optional

format of the result (e.g. “csr”)

Returns:
kronecker product in a sparse matrix format

Examples

>>> import numpy as np
>>> from scipy import sparse
>>> A = sparse.csr_matrix(np.array([[0, 2], [5, 0]]))
>>> B = sparse.csr_matrix(np.array([[1, 2], [3, 4]]))
>>> sparse.kron(A, B).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])
>>> sparse.kron(A, [[1, 2], [3, 4]]).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])