Sidechair

matrix.kron()

Browse the reference

Returns the Kronecker product of two matrices: a block matrix with a scaled copy of the second for every item of the first.

Try it in the editor

For an m by n matrix A and a p by q matrix B the result has m times p rows and n times q columns. The block at position (i, j) is A(i, j) multiplied by B.

Take A as [[1, 2]] and B as [[1, 1], [1, 1]]. The result has 2 rows and 4 columns, [[1, 1, 2, 2], [1, 1, 2, 2]]: a copy of B scaled by 1, then a copy scaled by 2.

It builds large structured matrices from small ones, as in some covariance and design-matrix constructions.

Syntax

Pine Script
matrix.kron(id1: matrix<int/float>, id2: matrix<int/float>) -> matrix<float>
matrix.kron(id1: matrix<int>, id2: matrix<int>) -> matrix<int>
matrix.kron(id2: matrix<int/float>) -> matrix<float>
matrix.kron(id2: matrix<int>) -> matrix<int>

Arguments

NameTypeDefaultDescription
id1matrix<int/float> or matrix<int>requiredThe matrix whose items scale the blocks: every item of it becomes one block of the result.
id2matrix<int/float> or matrix<int>requiredThe matrix copied into each block; its row and column counts set the size of every block.

Returns

  • matrix<float>: A new float matrix with m times p rows and n times q columns.
  • matrix<int>: A new integer matrix with m times p rows and n times q columns.
  • matrix<float>: A new float matrix, the receiving matrix expanded by blocks of id2.
  • matrix<int>: A new integer matrix, the receiving matrix expanded by blocks of id2.

Example

Pine Script2 by 2 with a 2 by 2Open in editor
//@version=6
indicator("matrix.kron: block product", overlay = false)
matrix<float> a = matrix.new<float>(2, 2, 1.0)
matrix<float> b = matrix.new<float>(2, 2, 2.0)
k = matrix.kron(a, b)
plot(matrix.rows(k), "Rows in the result")

See also

Runs on Sidechair