This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _construct / kron

function

scipy.sparse._construct:kron

source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_construct.py:780

Signature

def kron(A, B, format = None)

Summary

Sparse representation of the Kronecker product of A and B.

Extended Summary

Computes the Kronecker product, a composite sparse array made of blocks consisting of the second input array multiplied by each element of the first input array.

Parameters

A : sparse or dense array

first array of the product

B : sparse or dense array

second array of the product

format : str, optional (default: 'bsr' or 'coo')

format of the result (e.g. "csr") If None, choose 'bsr' for relatively dense 2D arrays and 'coo' for others

Returns

: sparse matrix or array

kronecker product in a sparse format. Returns a sparse matrix unless either A or B is a sparse array in which case returns a sparse array.

Examples

import numpy as np
import scipy as sp
A = sp.sparse.csr_array(np.array([[0, 2], [5, 0]]))
B = sp.sparse.csr_array(np.array([[1, 2], [3, 4]]))
sp.sparse.kron(A, B).toarray()
✓
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])
sp.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]])

Aliases

  • scipy.sparse.kron

Referenced by