Solved by Karo_Lina in post #3 
              
              
                Hi Alex, thanks for sharing this link. It helped me finding out where I did go wrong and at the end I got the same result with my implementation as with the jacobian function from pytorch. 
So in case anybody is reading this later on: My fault was that I calculated the gradient with respect to the n…