MCPcopy
hub / github.com/numpy/numpy / kron

Function kron

numpy/lib/_shape_base_impl.py:1039–1150  ·  view source on GitHub ↗

Kronecker product of two arrays. Computes the Kronecker product, a composite array made of blocks of the second array scaled by the first. Parameters ---------- a, b : array_like Returns ------- out : ndarray See Also -------- outer : The outer pr

(a, b)

Source from the content-addressed store, hash-verified

1037
1038@array_function_dispatch(_kron_dispatcher)
1039def kron(a, b):
1040 """
1041 Kronecker product of two arrays.
1042
1043 Computes the Kronecker product, a composite array made of blocks of the
1044 second array scaled by the first.
1045
1046 Parameters
1047 ----------
1048 a, b : array_like
1049
1050 Returns
1051 -------
1052 out : ndarray
1053
1054 See Also
1055 --------
1056 outer : The outer product
1057
1058 Notes
1059 -----
1060 The function assumes that the number of dimensions of `a` and `b`
1061 are the same, if necessary prepending the smallest with ones.
1062 If ``a.shape = (r0,r1,...,rN)`` and ``b.shape = (s0,s1,...,sN)``,
1063 the Kronecker product has shape ``(r0*s0, r1*s1, ..., rN*SN)``.
1064 The elements are products of elements from `a` and `b`, organized
1065 explicitly by::
1066
1067 kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN]
1068
1069 where::
1070
1071 kt = it * st + jt, t = 0,...,N
1072
1073 In the common 2-D case (N=1), the block structure can be visualized::
1074
1075 [[ a[0,0]*b, a[0,1]*b, ... , a[0,-1]*b ],
1076 [ ... ... ],
1077 [ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]]
1078
1079
1080 Examples
1081 --------
1082 >>> import numpy as np
1083 >>> np.kron([1,10,100], [5,6,7])
1084 array([ 5, 6, 7, ..., 500, 600, 700])
1085 >>> np.kron([5,6,7], [1,10,100])
1086 array([ 5, 50, 500, ..., 7, 70, 700])
1087
1088 >>> np.kron(np.eye(2), np.ones((2,2)))
1089 array([[1., 1., 0., 0.],
1090 [1., 1., 0., 0.],
1091 [0., 0., 1., 1.],
1092 [0., 0., 1., 1.]])
1093
1094 >>> a = np.arange(100).reshape((2,5,2,5))
1095 >>> b = np.arange(24).reshape((2,3,4))
1096 >>> c = np.kron(a,b)

Callers 2

test_return_typeMethod · 0.90
test_kroncompareMethod · 0.90

Calls 7

reshapeFunction · 0.90
matrixClass · 0.90
asanyarrayFunction · 0.85
expand_dimsFunction · 0.85
reshapeMethod · 0.80
arrayFunction · 0.50
maxFunction · 0.50

Tested by 2

test_return_typeMethod · 0.72
test_kroncompareMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…