Immutable Matrices¶

The standard Matrix class in SymPy is mutable. This is important for performance reasons but means that standard matrices can not interact well with the rest of SymPy. This is because the Basic object, from which most SymPy classes inherit, is immutable.

The mission of the ImmutableMatrix class is to bridge the tension between performance/mutability and safety/immutability. Immutable matrices can do almost everything that normal matrices can do but they inherit from Basic and can thus interact more naturally with the rest of SymPy.

You can turn any Matrix-like object into an ImmutableMatrix by calling the constructor

>>> from sympy import Matrix, ImmutableMatrix
>>> M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> M[1, 1] = 0
>>> IM = ImmutableMatrix(M)
>>> IM
[1, 2, 3]
[4, 0, 6]
[7, 8, 9]
>>> IM[1, 1] = 5
Traceback (most recent call last):
...
TypeError: Can not set values in Immutable Matrix. Use Matrix instead.


Matrix Expressions¶

ImmutableMatrix also inherits from MatrixExpr, allowing it to interact freely with SymPy’s Matrix Expression module.

Class Reference¶

class sympy.matrices.immutable_matrix.ImmutableMatrix[source]

Conjugate transpose or Hermitian conjugation.

as_mutable()

Returns a Mutable version of this Matrix

>>> from sympy import ImmutableMatrix
>>> X = ImmutableMatrix([[1,2],[3,4]])
>>> Y = X.as_mutable()
>>> Y[1,1] = 5 # Can set values in Y
>>> Y
[1, 2]
[3, 5]

conjugate()

By-element conjugation.

transpose
Matrix transposition
H
Hermite conjugation
D
Dirac conjugation
transpose()

Matrix transposition.

>>> from sympy import Matrix, I
>>> m=Matrix(((1,2+I),(3,4)))
>>> m
[1, 2 + I]
[3,     4]
>>> m.transpose()
[    1, 3]
[2 + I, 4]
>>> m.T == m.transpose()
True


conjugate
By-element conjugation