<jupyter_start><jupyter_text>Introduction to Python (Video companion) This notebook accompanies the video at https://www.youtube.com/watch?v=VDoGThKUn3kTo get the most out of this tutorial, it's recommended to watch the video first. Changing parts of the code and seeing how the output changes is a great way to learn from there. **The brief annotations below aren't meant to be a comprehensive explanation of the code** Find examples and help for using numpy at https://docs.scipy.org/doc/numpy/reference/routines.html<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Create a list as a variable<jupyter_code>a_variable = [1,2,3,4]
a_variable<jupyter_output><empty_output><jupyter_text>Two ways of adding entries to a list<jupyter_code>a_variable += [5]
a_variable.append(6)
a_variable<jupyter_output><empty_output><jupyter_text>Convert a list to a numpy array<jupyter_code>a_different_variable = np.array(a_variable)
a_different_variable<jupyter_output><empty_output><jupyter_text>Perform calculations on each entry of an array<jupyter_code>a_different_variable*10
(a_different_variable**2 + a_different_variable*6 + 7)**2
messy_calculation = (np.sin(a_different_variable) + np.cos(a_different_variable)**2 + np.log(a_different_variable) + np.exp(a_different_variable))
messy_calculation<jupyter_output><empty_output><jupyter_text>Finding the mean and standard deviation of an array<jupyter_code>np.mean(messy_calculation),np.std(messy_calculation)<jupyter_output><empty_output><jupyter_text>Generating arrays<jupyter_code>np.arange(5)
np.arange(1,11)
np.arange(1,11,2)<jupyter_output><empty_output><jupyter_text>Examples of accessing values in an array by index<jupyter_code>data = 2* np.arange(51)
data
data[5]
data
data[2]
data[len(data) - 1]
data[-1]<jupyter_output><empty_output><jupyter_text>Using slicing to take a specific part of an array data[start:end:step]<jupyter_code>data[:5]
data[1:5]
data[1:5:2]
data
data[-2:]<jupyter_output><empty_output><jupyter_text>Using for loops for [thing] in [list/array]:    [do stuff]<jupyter_code>sentence = 'Is energy conserved on the cosmological scale?'.split()
sentence
for word in sentence:
    print(word)
    print()
means = []

highest = 1001
batch_size = 100

loops = 200
for i in np.arange(loops):
    
    values = np.random.choice(highest,batch_size)
    average = np.mean(values)
    
    means += [average]
print(len(means))

#the first five values of means
means[:5]
np.mean(means),np.std(means)<jupyter_output><empty_output><jupyter_text>Basics of while loops while [something true]:        [run stuff]<jupyter_code>x = 3

while x < 6:
    print(x)
    print(x**2)
    print()
    
    x += 1

total = 0

i = 0

while total < 100:
    total += i
    
    i += 1
total, i<jupyter_output><empty_output><jupyter_text>if statements<jupyter_code>if np.random.choice(101) < 50:
    print('Heads')
else:
    print('Tails')<jupyter_output>Tails<jupyter_text>Functions<jupyter_code>def function_name(input1, input2, ..., inputn):
    [do stuff]
    return outputs
def hello():
    return 'Hello'
hello()
hello()
def is_odd(number):
    if np.abs(number) % 2 == 1:
        return True
    else:
        return False
is_odd(0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11375579598145286, 'fraction_numerical': 0.02071097372488408, 'mean_word_length': 5.959139784946236, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 52, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '454604', 'license': 'MIT', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1152, 'n_words': 263, 'path': 'Tutorial 1 - Python basics/Introduction to Python (Video companion).ipynb', 'repo_name': 'Mlawrence95/Segre-Work', 'size': '3235'}