kron¶
- paddle. kron ( x, y, name=None ) [source]
-
Compute the Kronecker product of two tensors, a composite tensor made of blocks of the second tensor scaled by the first. Assume that the rank of the two tensors, $X$ and $Y$ are the same, if necessary prepending the smallest with ones. If the shape of $X$ is [$r_0$, $r_1$, …, $r_N$] and the shape of $Y$ is [$s_0$, $s_1$, …, $s_N$], then the shape of the output tensor is [$r_{0}s_{0}$, $r_{1}s_{1}$, …, $r_{N}s_{N}$]. The elements are products of elements from $X$ and $Y$. The equation is: $$ output[k_{0}, k_{1}, …, k_{N}] = X[i_{0}, i_{1}, …, i_{N}] * Y[j_{0}, j_{1}, …, j_{N}] $$ where $$ k_{t} = i_{t} * s_{t} + j_{t}, t = 0, 1, …, N $$
- Parameters
-
x (Tensor) – the fist operand of kron op, data type: float16, float32, float64, int32 or int64.
y (Tensor) – the second operand of kron op, data type: float16, float32, float64, int32 or int64. Its data type should be the same with x.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
The output of kron, data type: float16, float32, float64, int32 or int64. Its data is the same with x.
- Return type
-
Tensor
Examples
import paddle x = paddle.to_tensor([[1, 2], [3, 4]], dtype='int64') y = paddle.to_tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype='int64') out = paddle.kron(x, y) print(out) # [[1, 2, 3, 2, 4, 6], # [ 4, 5, 6, 8, 10, 12], # [ 7, 8, 9, 14, 16, 18], # [ 3, 6, 9, 4, 8, 12], # [12, 15, 18, 16, 20, 24], # [21, 24, 27, 28, 32, 36]])