I am working with numpy arrays in Python. Is there a way to keep the entries of an array
as variables so that they follow proper matrix multiplication and other matrix functions (addition, determinant, etc.)?
For example:
import numpy as np
A = np.array([[a, b], [c, d]])
B = np.array([[e, f], [g, h]])
C = np.dot(A,B)
# C should be [ae+bf ag+bh]
# [ce+df cg+dh]
Also, as my matrix elements are complex in general, I would like the entries
of the type a+ib
where i
is interpreted as imaginary root of 1 rather than a variable. I can write the code defining my own functions, but is there a clean way of doing it?
Use
sympy
: