I have the following code for some symbolic calculations:
from sympy import *
import numpy
A = MatrixSymbol('A',2,2)
f = Matrix(A).det() # for example only, the actual function is of the same flavor
How do I substitute A
with an explicit Matrix of the same dimensions? I tried the following code but it doesn't produce desired result:
f.subs(A,Matrix(numpy.random.rand(2,2)))
Returned:
Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[0, 0]*Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[1, 1] - Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[0, 1]*Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[1, 0]