import tensorflow as tf

        grad = tf.reduce_mean(grad, 0)
        var = grad_and_vars[0][1]
        grad_and_var = (grad, var)
        average_grads.append(grad_and_var)
    return average_grads

def binary_mask(shape, p=0.7):
    samples = tf.random_uniform(shape, minval=0.0, maxval=1.0)
    mask = tf.less_equal(samples, p)
    return tf.cast(mask, tf.float32)

def weighted_arithmetic_mean(w, x):
    numer = tf.reduce_sum(w*x)
    denom = tf.reduce_sum(w)
    return tf.div(numer, denom)
