import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import scipy.stats as st
Types
2 + 2
4
= "hello, world" s
= 2
x type(x)
int
type(s)
str
= 2.2
y type(y)
float
= True
b type(b)
bool
type(None)
NoneType
= 'c'
c type(c)
str
= 2
s type(s)
int
Data Structures
= [1, 2.2, "edward", True] # list
l l
[1, 2.2, 'edward', True]
5)
l.append( l
[1, 2.2, 'edward', True, 5]
4] l[
5
= {"key": 1, 1: "value", (1, 2): "wow"} # dictionary or dict
d 1,2)] d[(
'wow'
"key"] d[
1
"math314"] = "is cool"
d[ d
{'key': 1, 1: 'value', (1, 2): 'wow', 'math314': 'is cool'}
= (1, 2, 3.4)
t t
(1, 2, 3.4)
Control Flow
if True:
print("yay")
else:
print("nay")
yay
if l:
print("what")
what
if ():
print("ah I get it")
for i in range(len(l)):
print(i, l[i])
0 1
1 2.2
2 edward
3 True
4 5
d.keys()
dict_keys(['key', 1, (1, 2), 'math314'])
d.values()
dict_values([1, 'value', 'wow', 'is cool'])
d.items()
dict_items([('key', 1), (1, 'value'), ((1, 2), 'wow'), ('math314', 'is cool')])
for k, v in d.items():
print(k, v)
key 1
1 value
(1, 2) wow
math314 is cool
= 0
c while True:
print(c)
if c > 10:
break
+= 1 c
0
1
2
3
4
5
6
7
8
9
10
11
*= 2
c /= 1.5
c **= 3
c c
3154.9629629629626
= 2
x **= 2
x x
4
if False:
print("a")
elif True:
print("b")
else:
print("c")
b
Functions
def f(h, j = 5, k = 6):
return h + j
1, j = 8) f(
9
1) f(
6
1, k = 2, j = 3) f(
4
2) f(
7
Class
class Table():
def __init__(self, num_legs = 4):
self.legs = num_legs
def num_legs(self):
return self.legs
= Table()
t = t.num_legs() x
= Table(num_legs = 7)
s s.num_legs()
7
Numpy
3) + 3) * 2 ) / 6) np.exp(((np.zeros(
array([2.71828183, 2.71828183, 2.71828183])
= np.random.default_rng(seed = 789427834294)
rng = rng.normal(size = 10) x
np.mean(x)
0.05685974974670359
np.std(x)
1.0161486486393296
= rng.normal(size = (3, 5))
X = 1) np.mean(X, axis
array([ 0.10255819, -0.85520091, -0.56674674])
= 1) np.std(X, axis
array([0.41042252, 0.72211726, 0.57281818])