matrix_props.is_square

Checks if the matrix is a square matrix.

Functions

is_square(mat)

Determine if a matrix is square [1].

Module Contents

matrix_props.is_square.is_square(mat)

Determine if a matrix is square [1].

A matrix is square if the dimensions of the rows and columns are equivalent.

Examples

Consider the following matrix

\[\begin{split}A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}\end{split}\]

our function indicates that this is indeed a square matrix.

>>> from toqito.matrix_props import is_square
>>> import numpy as np
>>> A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> is_square(A)
True

Alternatively, the following example matrix \(B\) defined as

\[\begin{split}B = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}\end{split}\]

is not square.

>>> from toqito.matrix_props import is_square
>>> import numpy as np
>>> B = np.array([[1, 2, 3], [4, 5, 6]])
>>> is_square(B)
False

References

[1] (1,2)

Wikipedia. Square matrix. URL: https://en.wikipedia.org/wiki/Square_matrix.

Raises:

ValueError – If variable is not a matrix.

Parameters:

mat (numpy.ndarray) – The matrix to check.

Returns:

Returns True if the matrix is square and False otherwise.

Return type:

bool