Matrix
A general-purpose complex-valued matrix class used internally by quantum state and channel representations. Matrix wraps an underlying complex matrix and provides basic linear-algebra operations.
Signature
Matrix(data: numpy.ndarray)Constructors
Default constructor
Matrix()Constructs an empty Matrix object.
From data
Matrix(data: numpy.ndarray)Constructs a Matrix from a 2-D complex numpy array (or an Eigen matrix).
| Parameter | Type | Description |
|---|---|---|
| data | numpy.ndarray | A 2-D array of complex numbers. |
Methods
ndarray
ndarray() -> numpy.ndarrayReturn the internal matrix data as a numpy.ndarray.
row_total
row_total() -> intReturn the number of rows in the matrix.
col_total
col_total() -> intReturn the number of columns in the matrix.
is_hermitian
is_hermitian() -> boolReturn True if the matrix is Hermitian, i.e.,
transpose
transpose() -> MatrixReturn the transpose of the matrix,
T
T() -> MatrixAlias for transpose(). Return the transpose of the matrix.
hermitian_conjugate
hermitian_conjugate() -> MatrixReturn the conjugate transpose (Hermitian adjoint) of the matrix,
adjoint
adjoint() -> MatrixAlias for hermitian_conjugate(). Return the conjugate transpose of the matrix.
L2
L2() -> floatReturn the L2 (Frobenius) norm of the matrix:
at
at(rowIdx: int, colIdx: int) -> complexReturn the element at the specified row and column index.
| Parameter | Type | Description |
|---|---|---|
| rowIdx | int | Row index (0-based). |
| colIdx | int | Column index (0-based). |
Operators
Equality
matrix_a == matrix_b -> boolReturn True if the two matrices have identical internal data.
Examples
import numpy as np
from pyqpanda3.quantum_info import Matrix
# Construct from a numpy array
data = np.array([[1+0j, 0+1j],
[0-1j, 1+0j]])
m = Matrix(data)
print(m.row_total()) # 2
print(m.col_total()) # 2
print(m.is_hermitian()) # True
# Transpose and adjoint
mt = m.transpose()
ma = m.adjoint()
# Access a single element
val = m.at(0, 1) # 0+1j
# Get the underlying numpy array
arr = m.ndarray()