<jupyter_start><jupyter_text>Comparison and bool values **Please run all cells before this cell, including the import cell at the top of the notebook.**<jupyter_code>x = 3
y = 4
x > y
10/2 != y
'Dog' > 'Cat'
'Dog' > 'Catastrophe' > 'Cat'
a = np.arange(11, 50)
a
a > 30
a == 15
def teen(x):
    return 13 <= x <= 19

[teen(10), teen(15), teen(20)]
ages = Table().with_column('Age', a)
ages = ages.with_column('Teenager', ages.apply(teen, 'Age'))
ages<jupyter_output><empty_output><jupyter_text>Combining bools **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>[x, y]
x < 2 or y > 4
not (x < 2 or x > 4)
True + True
(3 > 2) + (2 > 1)
False + False + False
sum([False, True, True, False, True])
ages
ages.column(1)
sum(ages.column(1))<jupyter_output><empty_output><jupyter_text>Predicates **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>ages
still_young = are.between(35, 40)
ages.where('Age', still_young)
still_young(38)
still_young(40)
ages.apply(still_young, 'Age')
sum(ages.apply(still_young, 'Age'))
ages.where('Age', teen)<jupyter_output><empty_output><jupyter_text>Choice **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>two_groups = make_array('treatment', 'control')
np.random.choice(two_groups)
np.random.choice(two_groups, 10)
np.random.choice(two_groups, 10)
outcomes = np.random.choice(two_groups, 10)
outcomes
outcomes
outcomes == 'control'
# sum(outcomes)
sum(outcomes == 'control')
sum(outcomes == 'treatment')<jupyter_output><empty_output><jupyter_text>Discussion Question **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>outcomes = np.random.choice(np.arange(6)+1, 1000) + np.random.choice(np.arange(6)+1, 1000)
Table().with_column("Outcome", outcomes).group(0).bar('Outcome')<jupyter_output><empty_output><jupyter_text>Print **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>def double(x):
    print('doubling', x)
    return 2 * x

def square(x):
    print('squaring', x)
    return x * x

double(square(double(5)))
print('one', end=' long ')
print('line')<jupyter_output>one long line<jupyter_text>Conditional Statements **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>def sign(x):
    print(x, 'is', end=' ')
    if x > 0:
        print('positive')
    if x < 0:
        print('negative')
    if x == 0:
        print('zero')

sign(3)
sign(-3)
sign(0)
def sign(x):
    print(x, 'is', end=' ')
    if x > 1e-15:
        print('positive')
    elif x < -1e-15:
        print('negative')
    elif x == 0:
        print('zero')
    else:
        print('really close to zero')

sign(3)
sign(-3)
sign(0)
sign(2**0.5 * 2 **0.5 - 2)<jupyter_output>3 is positive
-3 is negative
0 is zero
4.440892098500626e-16 is really close to zero<jupyter_text>For Statements **Please run all cells before this cell, including the previous example cells and the import cell at the top of the notebook.**<jupyter_code>np.append(make_array(1, 2, 3), 4)
np.append(make_array(1, 2, 3), 'four')
np.append(make_array(1, 2, 3), make_array(4, 5, 6))
np.arange(4)
for i in np.arange(4):
    print('iteration', i)
coin = make_array('heads', 'tails')
np.random.choice(coin)
sum(np.random.choice(coin, 100) == 'heads')
num_heads = make_array(sum(np.random.choice(coin, 100) == 'heads'))
num_heads
num_heads = np.append(num_heads, sum(np.random.choice(coin, 100) == 'heads'))
num_heads
for i in np.arange(10000):
    num_heads = np.append(num_heads, sum(np.random.choice(coin, 100) == 'heads'))
num_heads
len(num_heads)
t = Table().with_column('Heads in 100 coin flips', num_heads)
t.hist(bins=np.arange(30, 70, 1))
most = t.group(0).where(0, are.between(40, 60))
most
sum(most.column('count')) / t.num_rows * 100<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14815701292484443, 'fraction_numerical': 0.03709909047391096, 'mean_word_length': 5.056521739130435, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 42, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '570250', 'license': 'MIT', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1470, 'n_words': 432, 'path': 'Data8.1x/lec13.ipynb', 'repo_name': 'ayush1202/Data8x-Berkeley', 'size': '4178'}