Как использовать np.random.uniform () для реальных примеров - PullRequest
1 голос
/ 29 мая 2020

I want to solve this image question by using numpy

Что я пробовал

from numpy import random
import matplotlib.pyplot as plt

import seaborn as sns

sns.distplot(random.uniform(0,30, 5), hist=True)

plt.show()

Результат, который я получил Здесь показано 8 % и 12%, но мой обязательный ответ, согласно ручному прогнозу, составляет 16%. Я думаю, что меня смущает параметр size в `random.binomial () output

1 Ответ

0 голосов
/ 29 мая 2020

Насколько я понимаю, вы хотите смоделировать результат.

Попробуйте следующее

import numpy as np

# sample 100k uniform random values (it can be any large number) from 0 to 30
waiting_time = np.random.uniform(0, 30, size = 100_000) 

# caclulate the proportion that are between 10 and 15
np.mean((waiting_time >=10) & (waiting_time <= 15)) 
# will be around 0.166 i.e. around 16.6%.

График

import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(waiting_time)
plt.show();

# OR
import matplotlib.pyplot as plt
plt.hist(waiting_time);

enter image description here

...