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)
| 1066 | |
| 1067 | @array_function_dispatch(_kron_dispatcher) |
| 1068 | def kron(a, b): |
| 1069 | """ |
| 1070 | Kronecker product of two arrays. |
| 1071 | |
| 1072 | Computes the Kronecker product, a composite array made of blocks of the |
| 1073 | second array scaled by the first. |
| 1074 | |
| 1075 | Parameters |
| 1076 | ---------- |
| 1077 | a, b : array_like |
| 1078 | |
| 1079 | Returns |
| 1080 | ------- |
| 1081 | out : ndarray |
| 1082 | |
| 1083 | See Also |
| 1084 | -------- |
| 1085 | outer : The outer product |
| 1086 | |
| 1087 | Notes |
| 1088 | ----- |
| 1089 | The function assumes that the number of dimensions of `a` and `b` |
| 1090 | are the same, if necessary prepending the smallest with ones. |
| 1091 | If ``a.shape = (r0,r1,..,rN)`` and ``b.shape = (s0,s1,...,sN)``, |
| 1092 | the Kronecker product has shape ``(r0*s0, r1*s1, ..., rN*SN)``. |
| 1093 | The elements are products of elements from `a` and `b`, organized |
| 1094 | explicitly by:: |
| 1095 | |
| 1096 | kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN] |
| 1097 | |
| 1098 | where:: |
| 1099 | |
| 1100 | kt = it * st + jt, t = 0,...,N |
| 1101 | |
| 1102 | In the common 2-D case (N=1), the block structure can be visualized:: |
| 1103 | |
| 1104 | [[ a[0,0]*b, a[0,1]*b, ... , a[0,-1]*b ], |
| 1105 | [ ... ... ], |
| 1106 | [ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]] |
| 1107 | |
| 1108 | |
| 1109 | Examples |
| 1110 | -------- |
| 1111 | >>> np.kron([1,10,100], [5,6,7]) |
| 1112 | array([ 5, 6, 7, ..., 500, 600, 700]) |
| 1113 | >>> np.kron([5,6,7], [1,10,100]) |
| 1114 | array([ 5, 50, 500, ..., 7, 70, 700]) |
| 1115 | |
| 1116 | >>> np.kron(np.eye(2), np.ones((2,2))) |
| 1117 | array([[1., 1., 0., 0.], |
| 1118 | [1., 1., 0., 0.], |
| 1119 | [0., 0., 1., 1.], |
| 1120 | [0., 0., 1., 1.]]) |
| 1121 | |
| 1122 | >>> a = np.arange(100).reshape((2,5,2,5)) |
| 1123 | >>> b = np.arange(24).reshape((2,3,4)) |
| 1124 | >>> c = np.kron(a,b) |
| 1125 | >>> c.shape |