How does one calculate the (symbolic) gradient of a multivariate function in sympy?
Obviously I could calculate separately the derivative for each variable, but is there a vectorized operation that does this?
For example
m=sympy.Matrix(sympy.symbols('a b c d'))
Now for i=0..3 I can do:
sympy.diff(np.sum(m*m.T),m[i])
which will work, but I rather do something like:
sympy.diff(np.sum(m*m.T),m)
Which does not work ("AttributeError: ImmutableMatrix has no attribute _diff_wrt").
m
as a variable, which it does not know how to do. Just use a list comprehension overm
. – Sarge