On Sun, 31 May 2020 at 03:42, Giuseppe G. A. Celano
<[email protected]> wrote:
>
> I am trying to use very small matrices. Is there any way to calculate the 
> partial derivatives of "loss2" below?
>
> import numpy as np
> from sympy import *
>
> n, d, n2, d2 = 5, 7, 4, 3
>
> x = np.random.randn(n, d)
> y = np.random.randn(n, d2)
>
> w1 = MatrixSymbol("l", 7, 4)
> w1 = Matrix(w1)
>
> w2 = MatrixSymbol("p", 4, 3)
> w2 = Matrix(w2)
>
> h2 = x * w1
> predicted = h2 * w2
>
> loss2 = Matrix(np.square(predicted - y))

What do you want to differentiate with respect to?

You can use loss2.diff(w1[0, 0]) to differentiate with respect to the
upper left entry of w1.

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxQbuzUZ6bna%3DK5y04c8U0GksoOi2y-Fje7BMwEsiJYkxg%40mail.gmail.com.

Reply via email to