import numpy as np
# linear algebra
# matrix math
import pandas as pd
# data analysis
# financial analysis
# rows columns dataframe
# for structured data
import matplotlib.pyplot as plt
# plt is convention
import re
# regular expression
# text processing
# Need to install jupyterlab
from bs4 import BeautifulSoup # web scraping
# or
import bs4
import re # regular expressions text processing
import argparse # command line utility
# pytorch
import torch
from torch import nn # neural network nn
from torch import optim # optimizer
from torchvision import models # computer vision module
from PIL import Image # pillow image library
import json # json module
def neural_network(input, weight, bias):
prediction = input * weight + bias
return prediction
# * can mean dot product, matrix multiplication, convolution
# Not a simple multiplication
<p>Demonstrating p tag </p>
() => {
console.log("anonymous");
}
# cool markdown
`code` in markdown
f = open('mytextfile.txt') # f for file
for line in f:
line = line.rstrip()
print(line)
f.close() # close is important
See one hot encoding flash card for explanation
doc1 = ['cat']
doc2 = ['cat', 'dog']
doc3 = ['bird']
doc4 = ['dog']
vocab_matrix =[
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
]
def get_min(node):
if node is None:
raise ValueError
if node.left is None:
raise ValueError
n = node
while n.left:
n = n.left
return n.val
Verify python version
Verify pip version
python --version
pip --version
python3
py
Run python script on windows
py my_python_script.py
import matplotlib.pyplot as plt
# create mock data
x = [i for i in range(5)]
y = [2*xx for xx in x]
plt.plot(x,y) # simple plot
plt.title('Simple Matplotlib') #add title
plt.ylabel('y') #add y label
plt.xlabel('x')
plt.show() # display the plot
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
# cool markdown
`code` in markdown
class Node(object):
def __init__(self, data):
self.data = data
self.neighbors = []
# variation
class Node(object):
def __init__(self, val):
self.val = val
self.children = []
# variation
class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# some basic operations
# track visited node
node_completed = {}
# init a node
root = 10
node = Node(root)
node_completed['root'] = node
# retrieve values
node_completed['root'].data
nbrs = node_completed['root'].neighbors
nbrs
# explore all neighbors,
# iterate through the neighbors list
# for n in root.neighbors:
'''
1
/ \
/ \
2 3
/ \ / \
None None None None
#leaves
Breadth first search (BFS) is the most straight forward print out 1, 2, 3
'''
# cool markdown
`code` in markdown
def search_list(nums, target):
if len(nums) > 0:
for num in nums:
val = num
if val == target:
return True
return False
# init a new set, assign it to a variable
# add a number to it and display that variable
my_set = set()
my_set.add(1)
my_set # --> returns {1}
num_list = [1, 2, -99, 8, 2]
# Uniqtech Co. min tutorial
def state_machine(num_list):
min_val = num_list[0]
# alternative : min_val = float('inf')
for num in num_list:
if num < min_val:
min_val = num
return min_val
state_machine(num_list)
# >>> -99
# Uniqtech Co. min tutorial