# 4 examples of 'np.random.exponential' in Python

Every line of 'np.random.exponential' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``344def _exponential_internal(scale: float,345                          n: int,346                          antithetic: bool = False) -&gt; ndarray:347    u = rand(n)348    u = minimum(u, 1.0 - np.finfo(np.float32).eps)349    x: ndarray = log(1.0 - u) * (-scale)350    return x``
``228def exponential(x):229    """Exponential's function.230231    It can be used with 'n' variables and has minimum at -1.232    Also, it is expected to be within [-1, 1] bounds.233234    Args:235        x (np.array): An n-dimensional input array.236237    Returns:238        y = -exp(-0.5 * sum(x^2))239240    """241242    # Calculating Sphere's function243    s = sphere(x)244245    return -np.exp(-0.5 * s)``
``8def sampleFromExponential((lambdaParam, size)):9    return numpy.random.exponential(lambdaParam, size)``
``1712def random(self, array_or_shape):1713    """1714    Generate a random sample with the same type as the layer.1715    For an Exponential layer, draws from the exponential distribution1716    with the rate determined by the params attribute.17171718    Used for generating initial configurations for Monte Carlo runs.17191720    Args:1721        array_or_shape (array or shape tuple):1722            If tuple, then this is taken to be the shape.1723            If array, then its shape is used.17241725    Returns:1726        tensor: Random sample with desired shape.17271728    """1729    try:1730        shape = be.shape(array_or_shape)1731    except Exception:1732        shape = array_or_shape17331734    r = self.rand(shape)1735    return be.divide(self.params.loc, -be.log(r))``