Ho,
I did not understood your goal.
So yes you can do that but you will need a full Jacobian so you will need to do a for loop as you mentioned. Also a small code sample to help you get full Jacobian can be found here 7.
Note that this gradient penalty will not guarantee that the resulting network will be monotonic non-decreasing. It will just penalize it if it is not.