toqito.matrix_props.is_square

Checks if the matrix is a square matrix.

Module Contents

toqito.matrix_props.is_square.is_square(mat)[source]

Determine if a matrix is square [@WikiSqMat].

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

Examples

Consider the following matrix

[
A = begin{pmatrix}

1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9

end{pmatrix}

]

our function indicates that this is indeed a square matrix.

```python exec=”1” source=”above” import numpy as np from toqito.matrix_props import is_square

A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

print(is_square(A)) ```

Alternatively, the following example matrix (B) defined as

[
B = begin{pmatrix}

1 & 2 & 3 \ 4 & 5 & 6

end{pmatrix}

]

is not square.

```python exec=”1” source=”above” import numpy as np from toqito.matrix_props import is_square

B = np.array([[1, 2, 3], [4, 5, 6]])

print(is_square(B)) ```

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