matrix_ops.calculate_vector_matrix_dimension

Calculate the (common) dimension of a set of vectors or matrices.

Module Contents

Functions

calculate_vector_matrix_dimension(item)

Calculate the dimension of a vector or a square matrix, including 2D representations of vectors.

matrix_ops.calculate_vector_matrix_dimension.calculate_vector_matrix_dimension(item)

Calculate the dimension of a vector or a square matrix, including 2D representations of vectors.

This function determines the dimension of the provided item, treating 1D arrays as vectors, 2D arrays with one dimension being 1 as vector representations, and square 2D arrays as density matrices. The dimension is the length for vectors and the square of the side length for density matrices.

Parameters:

item (numpy.ndarray) – The item whose dimension is being calculated. Can be a 1D array (vector), a 2D array representing a vector with one dimension being 1, or a square 2D array (density matrix).

Returns:

int The dimension of the item. For vectors (1D or 2D representations), it’s the length. For square matrices, it’s the square of the size of one side.

Raises:

ValueError – If the input is not a numpy array, not a 1D array (vector), a 2D array representing a vector, or a square 2D array (density matrix).

Returns:

The dimension of the vector or matrix.

Return type:

int