简体   繁体   中英

Imaginary Matrices in Sympy using MatrixSymbol

Multiplying a matrix with the imaginary unit raises an exception, ie,

import sympy as sy 

M = sy.MatrixSymbol('M', 2, 2)  
print(sy.I * M)

raises the exception

TypeError: Invalid comparison of non-real I

My current workaround is to replace sy.I with an i = sy.Symbol('i') . Is there a better way to use the MatrxixSymbol together with imaginary expressions? Thanks.

PS: Conda Python 3.7.6 and Sympy version 1.5.1 is used.

This is a bug in SymPy. I've opened github.com/sympy/sympy/issues/18743 for it. The bug only occurs when printing the expression, so you can work around it by avoiding printing the expression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM