SciPy

scipy.sparse.kron

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

kronecker product of sparse matrices A and B

Parameters:

A : sparse or dense matrix

first matrix of the product

B : sparse or dense matrix

second matrix of the product

format : str, optional

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

Returns:

kronecker product in a sparse matrix format

Examples

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

Previous topic

scipy.sparse.identity

Next topic

scipy.sparse.kronsum