<jupyter_start><jupyter_text>Coin Flips and Die RollsUse NumPy to create simulations and compute proportions for the following outcomes. The first one is done for you.**Please note again that we are using 0 to represent heads, and 1 to represent tails.**<jupyter_code># import numpy
import numpy as np
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. Two fair coin flips produce exactly two heads<jupyter_code># simulate 1 million tests of two fair coin flips
tests = np.random.randint(2, size=(int(1e6), 2))

# sums of all tests
test_sums = tests.sum(axis=1)

# proportion of tests that produced exactly two heads
(test_sums == 0).mean()<jupyter_output><empty_output><jupyter_text>2. Three fair coin flips produce exactly one head<jupyter_code># simulate 1 million tests of three fair coin flips
tests = np.random.randint(2,size=(int(1e6),3))

# sums of all tests
test_sums = tests.sum(axis=1)

# proportion of tests that produced exactly one head
(test_sums ==0).mean()<jupyter_output><empty_output><jupyter_text>3. Three biased coin flips with P(H) = 0.6 produce exactly one head<jupyter_code># simulate 1 million tests of three biased coin flips
# hint: use np.random.choice()
tests = np.random.choice([0,1],p=[.6,.4],size=(int(1e6)))
print(tests)
# sums of all tests
test_sums = tests.sum()

# proportion of tests that produced exactly one head
test_sums/len(tests)<jupyter_output>[1 0 1 ..., 1 0 1]<jupyter_text>4. A die rolls an even number<jupyter_code># simulate 1 million tests of one die roll
tests = np.random.choice([1,2,3,4,5,6],size=(int(1e6)))
print(tests)
# proportion of tests that produced an even number
print(len(tests[tests%2==0])/len(tests))<jupyter_output>[2 2 1 ..., 6 2 3]
0.500038<jupyter_text>5. Two dice roll a double<jupyter_code># simulate the first million die rolls
first = np.random.choice([1,2,3,4,5,6],size=(int(1e6)))
print(first)
# simulate the second million die rolls
second = np.random.choice([1,2,3,4,5,6],size=(int(1e6)))
print(second)
# proportion of tests where the 1st and 2nd die rolled the same number<jupyter_output>[6 1 2 ..., 6 5 1]
[3 3 1 ..., 5 5 5]
{'fraction_non_alphanumeric': 0.12181303116147309, 'fraction_numerical': 0.042492917847025496, 'mean_word_length': 5.663522012578617, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '356256', 'license': 'Unlicense', 'n_tokens_mistral': 788, 'n_tokens_neox': 731, 'n_words': 243, 'path': '03 Stats/08 Python Prob Practice/probability.ipynb', 'repo_name': 'Alashmony/DA_Udacity', 'size': '2118'}