(X, rate=0.3)
return tf.add(tf.multiply(X, a), c)
Take an input tensor and add salt-and-pepper noise, where a fraction
    `rate` of elements of X (chosen at random) is set to zero or one according
    to a fair coin flip.

    Parameters
    ----------
    X : Tensor/Placeholder
        Input to corrupt.
    rate : float
        Fraction of elements to be set to zero or one.

    Returns
    -------
    x_corrupted : Tensor
        Input tensor with `rate` fraction of values corrupted.
Take an input tensor and add salt-and-pepper noise, where a fraction
    `rate` of elements of X (chosen at random) is set to zero or one according
    to a fair coin flip.
Take an input tensor and add salt - and - pepper noise where a fraction rate of elements of X ( chosen at random ) is set to zero or one according to a fair coin flip .
def salt_and_pepper_noise(X, rate=0.3):
    """Take an input tensor and add salt-and-pepper noise, where a fraction
    `rate` of elements of X (chosen at random) is set to zero or one according
    to a fair coin flip.

    Parameters
    ----------
    X : Tensor/Placeholder
        Input to corrupt.
    rate : float
        Fraction of elements to be set to zero or one.

    Returns
    -------
    x_corrupted : Tensor
        Input tensor with `rate` fraction of values corrupted.
    """
    a = binomial(shape=tf.shape(X), p=1 - rate)
    b = binomial(shape=tf.shape(X), p=0.5)
    z = tf.zeros(tf.shape(X), dtype='float32')
    c = tf.where(tf.equal(a, z), b, z)
    return tf.add(tf.multiply(X, a), c)
def salt_and_pepper_noise ( X , rate = 0.3 ) : a = binomial ( shape = tf . shape ( X ) , p = 1 - rate ) b = binomial ( shape = tf . shape ( X ) , p = 0.5 ) z = tf . zeros ( tf . shape ( X ) , dtype = 'float32' ) c = tf . where ( tf . equal ( a , z ) , b , z ) return tf . add ( tf . multiply ( X , a ) , c )