TOEPLITZ

Constructs a Toeplitz matrix, which is a matrix where each descending diagonal from left to right is constant.

Excel Usage

=TOEPLITZ(column, row)
  • column (list[list], required): First column of the matrix.
  • row (list[list], optional, default: null): First row of the matrix. If omitted, the matrix is assumed symmetric/Hermitian based on the column.

Returns (list[list]): 2D array representing the Toeplitz matrix.

Example 1: Symmetric Toeplitz matrix

Inputs:

column
1 2 3

Excel formula:

=TOEPLITZ({1,2,3})

Expected output:

Result
1 2 3
2 1 2
3 2 1
Example 2: Asymmetric Toeplitz matrix

Inputs:

column row
1 2 3 1 4 5

Excel formula:

=TOEPLITZ({1,2,3}, {1,4,5})

Expected output:

Result
1 4 5
2 1 4
3 2 1
Example 3: Toeplitz matrix from column-style input

Inputs:

column
1
2
3
4

Excel formula:

=TOEPLITZ({1;2;3;4})

Expected output:

Result
1 2 3 4
2 1 2 3
3 2 1 2
4 3 2 1
Example 4: Toeplitz matrix from scalar column value

Inputs:

column
6

Excel formula:

=TOEPLITZ(6)

Expected output:

6

Python Code

import numpy as np
from scipy.linalg import toeplitz as scipy_toeplitz

def toeplitz(column, row=None):
    """
    Construct a Toeplitz matrix.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.toeplitz.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        column (list[list]): First column of the matrix.
        row (list[list], optional): First row of the matrix. If omitted, the matrix is assumed symmetric/Hermitian based on the column. Default is None.

    Returns:
        list[list]: 2D array representing the Toeplitz matrix.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        column = to2d(column)
        if not isinstance(column, list) or not all(isinstance(row, list) for row in column):
            return "Error: column must be a 2D list"

        flat_column = []
        for row_values in column:
            for value in row_values:
                try:
                    flat_column.append(float(value))
                except (TypeError, ValueError):
                    return "Error: column must contain only numeric values"

        if not flat_column:
            return "Error: column must contain at least one numeric value"

        c = np.array(flat_column, dtype=float)

        if row is not None:
            row = to2d(row)
            if not isinstance(row, list) or not all(isinstance(row_values, list) for row_values in row):
                return "Error: row must be a 2D list"

            flat_row = []
            for row_values in row:
                for value in row_values:
                    try:
                        flat_row.append(float(value))
                    except (TypeError, ValueError):
                        return "Error: row must contain only numeric values"

            if not flat_row:
                return "Error: row must contain at least one numeric value"

            r = np.array(flat_row, dtype=float)
        else:
            r = None

        res = scipy_toeplitz(c, r)
        return res.tolist()

    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

First column of the matrix.
First row of the matrix. If omitted, the matrix is assumed symmetric/Hermitian based on the column.