import numpy as np # %% Number of trials: n = 10 # %% Params of choice(): sample_space = np.array([1, 2, 3, 4, 5, 6]) sample_size = 1 replace = True prob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6] # %% Array for storing the population: x_pop = np.zeros(n) # %% For loop realizing the n generated samples: for k in range(0, n): # Sample number k: x_k = np.random.choice(sample_space, sample_size, replace, prob) # Storing sample_k: x_pop[k] = int(x_k) # %% Displaying the data series: # print('x_pop =', x_pop.astype(int)) # %% Statistical measures: m_x = np.sum(x_pop)/n # Mean var_x = np.sum((x_pop - m_x)**2)/(n - 1) # Variance std_x = np.sqrt(var_x) # Standard deviation # %% Displaying results: print('m_x =', f'{m_x:.2f}') print('var_x =', f'{var_x:.2f}') print('std_x =', f'{std_x:.2f}')