Is there a way to output an equation include equal sign with sympy?

Viewed 643

with sympy

A = Matrix([[1,1],[2,2],[0,0]])
MatMul(A.T, A, evaluate=False)

I can output an equation like this

enter image description here

is there a way to output an equation containing an equal sign like this?

enter image description here

2 Answers

The following should work. Eq is an Equality container that prints with an = separating the left and rhs.

>>> pprint(Eq(MatMul(A.T, A, evaluate=False), A.T*A))

You can also get the latex representation of the same by replacing pprint with latex.

For ipython users (and vscode with #%% separators) this will produce a nice graphical display. The evaluate=False in the Eq prevents evaluation and reduction of the result to True or False..

display(Eq(MatMul(A.T, A, evaluate=False), A.T*A, evaluate=False))

Another useful variant is to display the variable name like so:

display(Eq(S('A'),A, evaluate=False))
Related