bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / _external / array_api_extra / _delegation / kron
function
scipy._external.array_api_extra._delegation:kron
source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/_delegation.py:656
Signature
def kron(a: Array | complex, b: Array | complex, /, xp: ArrayNamespace | None = None) → ArraySummary
Kronecker product of two arrays.
Extended Summary
Computes the Kronecker product, a composite array made of blocks of the second array scaled by the first.
Equivalent to numpy.kron for NumPy arrays.
Parameters
a, b: Array | int | float | complexInput arrays or scalars. At least one must be an array.
xp: array_namespace, optionalThe standard-compatible namespace for
aandb. Default: infer.
Returns
: arrayThe Kronecker product of
aandb.
Notes
The function assumes that the number of dimensions of a and b are the same, if necessary prepending the smallest with ones. If a.shape = (r0,r1,..,rN) and b.shape = (s0,s1,...,sN), the Kronecker product has shape (r0*s0, r1*s1, ..., rN*SN). The elements are products of elements from a and b, organized explicitly by
kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN]where
kt = it * st + jt, t = 0,...,NIn the common 2-D case (N=1), the block structure can be visualized
[[ a[0,0]*b, a[0,1]*b, ... , a[0,-1]*b ], [ ... ... ], [ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]]
Examples
import array_api_strict as xp import array_api_extra as xpx xpx.kron(xp.asarray([1, 10, 100]), xp.asarray([5, 6, 7]), xp=xp)⚠
Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:kron[0]>", line 1, in <module>
xpx.kron(xp.asarray([1, 10, 100]), xp.asarray([5, 6, 7]), xp=xp)
^^^
NameError: name 'xpx' is not defined
xpx.kron(xp.asarray([5, 6, 7]), xp.asarray([1, 10, 100]), xp=xp)
⚠Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:kron[0]>", line 1, in <module>
xpx.kron(xp.asarray([5, 6, 7]), xp.asarray([1, 10, 100]), xp=xp)
^^^
NameError: name 'xpx' is not defined
xpx.kron(xp.eye(2), xp.ones((2, 2)), xp=xp)
⚠Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:kron[0]>", line 1, in <module>
xpx.kron(xp.eye(2), xp.ones((2, 2)), xp=xp)
^^^
NameError: name 'xpx' is not defined
a = xp.reshape(xp.arange(100), (2, 5, 2, 5)) b = xp.reshape(xp.arange(24), (2, 3, 4)) c = xpx.kron(a, b, xp=xp) c.shape⚠
Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:kron[0]>", line 1, in <module>
c.shape
^
NameError: name 'c' is not defined
I = (1, 3, 0, 2) J = (0, 2, 1) J1 = (0,) + J # extend to ndim=4✓
S1 = (1,) + b.shape K = tuple(xp.asarray(I) * xp.asarray(S1) + xp.asarray(J1)) c[K] == a[I]*b[J]⚠
Traceback (most recent call last):
File "<doctest scipy._external.array_api_extra._delegation:kron[0]>", line 1, in <module>
c[K] == a[I]*b[J]
^
NameError: name 'c' is not defined
Aliases
scipy.differentiate.xpx.kron