Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- # Number of simulations
- sims = 1000000
- # Generate random samples from uniform distributions
- A = np.random.uniform(1, 5, sims)
- B = np.random.uniform(2, 6, sims)
- # Calculate the sum of corresponding elements
- duration = A + B
- # Plot a histogram of the duration array
- plt.figure(figsize=(3, 1.5))
- plt.hist(duration, density=True)
- # Add a vertical red line at the value 9
- plt.axvline(9, color='r')
- # Show the plot
- plt.show()
- # Print the proportion of elements in duration that are greater than 9
- print((duration > 9).sum() / sims)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement