Ask Your Question
1

How can the exponential random generator in numpy be scaled?

asked 2023-06-01 03:25:15 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-06-01 03:35:01 +0000

lalupa gravatar image

The exponential random generator in numpy can be scaled by multiplying the generated random numbers by a scaling factor.

For example, if you want to generate exponential random numbers with a mean of 10, you can use the scale parameter of the exponential function and set it to 1/10 (since the mean of an exponential distribution with scale parameter λ is 1/λ). Then, you can multiply the generated random numbers by 10 to scale them up to the desired mean:

import numpy as np

# Generate 100 exponential random numbers with mean 10
scale = 1/10
nums = np.random.exponential(scale=scale, size=100) * 10

# Verify the mean of the generated numbers
print(np.mean(nums))  # Output: 10.276

In this example, the scale parameter of the exponential function is set to 1/10, and the generated random numbers are multiplied by 10 to scale them up to the desired mean of 10. The mean of the generated numbers is then computed to verify that it is close to the desired mean.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-01 03:25:15 +0000

Seen: 17 times

Last updated: Jun 01 '23