toqito.matrix_props.has_same_dimension

Checks if the dimensions of list of vectors or matrices are equal.

Module Contents

toqito.matrix_props.has_same_dimension.has_same_dimension(items)[source]

Check if all vectors or matrices in a list have the same dimension.

For a vector (1D array), the dimension is its length. For a matrix, the dimension can be considered as the total number of elements (rows x columns) for non-square matrices, or simply the number of rows (or columns) for square matrices. The function iterates through the provided list and ensures that every item has the same dimension.

Examples

Check a list of vectors with the same dimension:

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

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

print(has_same_dimension(vectors)) ```

Check a list of matrices with the same dimension:

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

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

print(has_same_dimension(matrices)) ```

Check a list containing items of different dimensions:

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

mixed = [np.array([1, 2, 3]), np.array([[1, 0], [0, 1]])]

print(has_same_dimension(mixed)) ```

Raises:

ValueError – If the input list is empty.

Parameters:
  • items (list[numpy.ndarray]) – A list containing vectors or matrices. Vectors are represented as 1D numpy arrays, and matrices are

  • arrays. (represented as 2D numpy)

Returns:

Returns True if all items in the list have the same dimension, False otherwise.

Return type:

bool