qalgebra.core.matrix_algebra module¶
Matrices of Expressions.
Summary¶
Classes:
Matrix of Expressions. |
Functions:
Generate the operator matrix with quadrants |
|
Generalizes the diagonal matrix creation capabilities of numpy.diag to |
|
Generalizes numpy.hstack to |
|
Generate the N-dimensional identity matrix. |
|
Generalizes numpy.vstack to |
|
Generalizes |
__all__
: Matrix
, block_matrix
, diagm
, hstackm
, identity_matrix
, vstackm
, zerosm
Reference¶
-
class
qalgebra.core.matrix_algebra.
Matrix
(m)[source]¶ Bases:
object
Matrix of Expressions.
-
matrix
= None¶
-
property
shape
¶ The shape of the matrix
(nrows, ncols)
.
-
property
block_structure
¶ For square matrices this gives the block (-diagonal) structure of the matrix as a tuple of integers that sum up to the full dimension.
- Return type
-
property
is_zero
¶ Are all elements of the matrix zero?
-
conjugate
()[source]¶ The element-wise conjugate matrix.
This is defined only if all the entries in the matrix have a defined conjugate (i.e., they have a conjugate method). This is not the case for a matrix of operators. In such a case, only an elementwise
adjoint()
would be applicable, but this is mathematically different from a complex conjugate.- Raises
NoConjugateMatrix – if any entries have no conjugate method
-
property
real
¶ Element-wise real part.
- Raises
NoConjugateMatrix – if entries have no conjugate method and no other way to determine the real part
Note
A mathematically equivalent way to obtain a real matrix from a complex matrix
M
is:(M.conjugate() + M) / 2
However, the result may not be identical to
M.real
, as the latter tries to convert elements of the matrix to real values directly, if possible, and only uses the conjugate as a fall-back
-
property
imag
¶ Element-wise imaginary part.
- Raises
NoConjugateMatrix – if entries have no conjugate method and no other way to determine the imaginary part
Note
A mathematically equivalent way to obtain an imaginary matrix from a complex matrix
M
is:(M.conjugate() - M) / (I * 2)
with same same caveats as
real
.
-
property
T
¶ Alias for
transpose()
.
-
adjoint
()[source]¶ Adjoint of the matrix.
This is the transpose and the Hermitian adjoint of all elements.
-
dag
()¶ Adjoint of the matrix.
This is the transpose and the Hermitian adjoint of all elements.
-
element_wise
(func, *args, **kwargs)[source]¶ Apply a function to each matrix element and return the result in a new operator matrix of the same shape.
- Parameters
func (callable) – A function to be applied to each element. It must take the element as its first argument.
args – Additional positional arguments to be passed to func
kwargs – Additional keyword arguments to be passed to func
- Returns
Matrix with results of func, applied element-wise.
- Return type
-
series_expand
(param, about, order)[source]¶ Expand the matrix expression as a truncated power series in a scalar parameter.
-
substitute
(var_map)[source]¶ Perform a substitution in all element of the matrix.
Equivalent to applying
substitute()
element-wise.- Returns
Matrix with substitutions
- Return type
-
property
free_symbols
¶ Free symbols, across all elements.
-
property
space
¶ Combined Hilbert space of all matrix elements.
If none of the elements have an associated hilbert space,
TrivialSpace
.
-
-
qalgebra.core.matrix_algebra.
block_matrix
(A, B, C, D)[source]¶ Generate the operator matrix with quadrants
\[\begin{split}\begin{pmatrix} A B \\ C D \end{pmatrix}\end{split}\]
-
qalgebra.core.matrix_algebra.
diagm
(v, k=0)[source]¶ Generalizes the diagonal matrix creation capabilities of numpy.diag to
Matrix
objects.