I dont understand the logic of the solution. The final return is a list of chi-squared_values, but in the for loop, we came up with only one number instead of a list.
Screen Link: https://app.dataquest.io/m/99/chi-squared-tests/4/generating-a-distribution
My understanding of the below code is to randomly take 32561 numbers between 0-1, if value >0.5 then we assign them as male, others are assigned to female. Then we count male and female. We came up 2 numbers, based on these 2 number we calculated
female_diffadded these 2 numbers together, then we have one number
chi_squared.After appending it to the
chi_squared_values, why it becomes a list eventually…
for i in range(1000): sequence = random((32561,)) sequence[sequence < .5] = 0 sequence[sequence >= .5] = 1 male_count = len(sequence[sequence == 0]) female_count = len(sequence[sequence == 1]) male_diff = (male_count - 16280.5) ** 2 / 16280.5 female_diff = (female_count - 16280.5) ** 2 / 16280.5 chi_squared = male_diff + female_diff chi_squared_values.append(chi_squared)