import tensorflow as tf

    for i in range (dim):

        dg_i = tf.gradients(flat_grads[i], par) #for each element of grads evaluate the gradients
        dg_i_flat = flatten(dg_i) #flatten the resulting hessian onto a 1 d array
