# Tensorflow loop to analyze gradients derived from MRI and PET images

The code shown below takes the partial derivative of each pixel of the output fused image of a neural network with respect to input image of the neural network using tensorflow's tf.gradients(Y, X) and compute a Jacobian matrix for each of the two input images MRI and PET. However, the code is really slow since I currently define a for loop by iterating through each pixel to compute the Jacobian matrix.

jacob_matrix_mri = np.zeros((65536,256,256))
jacob_matrix_pet = np.zeros((65536,256,256))

count = 0
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver.restore(sess,'/home/nora/Desktop/MBIA 2019/Checkpoint/')
for i in range(image_width):
for j in range(image_length):