Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Part One/1-1-introduction-to-python-programming.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-11-binary-representation.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-2-python-numeric-types.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-3-strings-and-text-input-output.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-4-lists.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-5-conditions-and-loops.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-6-functions.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-7-tuples-and-dictionaries.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Part One/1-8-sets-and-hashing.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Part Two/2-1-motto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

path = os.path.dirname(os.path.abspath(__file__))

file = open(path+'/'+'motto.txt','w')
file.write("Fiat Lux!")


file.close()

file = open(path+'/'+'motto.txt','a')
file.write("\nLight Speed!")
file.close()
25 changes: 25 additions & 0 deletions Part Two/2-2-Flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from matplotlib import image
from matplotlib import pyplot
import os

# Read an image file
path = os.path.dirname(os.path.abspath(__file__))
wales_flag = path + '/' + 'wales-flag-xs.jpg'
lenna = path + '/' + 'lenna.bmp'
bottom = image.imread(lenna)
top = image.imread(wales_flag)
# Display image information



# Add some color boundaries to modify an image array
edited = bottom.copy()
for width in range(top.shape[1]):
for height in range(top.shape[0]):
edited[height][512-250+width] = [
(top[height][width][0]),
(top[height][width][1]),
(top[height][width][2]),
]
image.imsave(path+'/'+'lenna_with_dragon.jpg', edited)
pyplot.imshow(edited)
43 changes: 43 additions & 0 deletions Part Two/2-3-sense-sensibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import PyPDF2
import os
import string
import time

start_time = time.time()

# Open PDF file
path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(path, 'Sense_and_sensibility.pdf')
file_handle = open(file_path, 'rb')
pdfReader = PyPDF2.PdfReader(file_handle)

frequency_table = {}

# Iterating thru pages
for page_num in range(len(pdfReader.pages)):
page_object = pdfReader.pages[page_num]
page_text = page_object.extract_text()
words = page_text.split("\n")
for extracted_string in words:
# Clean the selected word
list_of_string = extracted_string.split()
for chars in list_of_string:
if chars.isdigit():
pass
if chars.isalpha():
if chars in frequency_table:
frequency_table[chars] += 1
else:
frequency_table[chars] = 1
else:
chars = chars[:-1]
if chars in frequency_table:
frequency_table[chars] += 1
else:
frequency_table[chars] = 1
end_time = time.time()
file_handle.close()

total_distinct_words = len(frequency_table)
print("Total number of unique words: " + str(total_distinct_words))
print ("time taken: " + str(end_time-start_time))
73 changes: 73 additions & 0 deletions Part Two/3-1.ipynb

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Part Two/3-2-MatrixDotProd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np

p1 = np.array([[6,-9,1],[4,24,8]])
p1result = p1*2

mi = np.eye(2)
m2result = mi@p1

p2 = np.array([[4,3],[3,2]])
p3 = np.array([[-2,3],[3,-4]])

rop3p2 = p2@p3
print(rop3p2)
8 changes: 8 additions & 0 deletions Part Two/3-3-Slicing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np
a3 = np.array([list(range(i * 10,i * 10+6)) for i in range(6)])
print(a3)
a = a3[:,1]
b=a3[1, 2:4]
c=a3[2:4, 4:]
d=a3[2::2, ::2]
print(a,b,c,d)
21 changes: 21 additions & 0 deletions Part Two/3-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np

def swap_Rows(M,a,b):
if a >= M.shape[0] or b >= M.shape[0] or a<0 or b<0:
raise IndexError("Row Indicies are out of bounds")
temp = M[a].copy()
M[[a,b],:]=M[[b,a],:]


return M
def swap_Columns(M,a,b):
if a >= M.shape[1] or b >= M.shape[1] or a<0 or b<0:
raise IndexError("Row Indicies are out of bounds")
temp = M[:,a].copy()
M[:,a]=M[:,b]
M[:,b] = temp
M[:,[a,b]]=M[:,[b,a]]
return M

v = np.array([[0,1,2],[3,4,5]])
-
12 changes: 12 additions & 0 deletions Part Two/3-5-MatrixArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import numpy as np
sample_list = [1,2,3,4,5,6,7,8,9,10,11,12]
def set_array(l,r,c):
sample_array = np.array(l)
shaped_array = sample_array.reshape(r,c)
return(shaped_array)

x=set_array(sample_list,4,3)
y=set_array(sample_list,3,4)

z=x@y
print(z)
Binary file added Part Two/Sense_and_sensibility.pdf
Binary file not shown.
File renamed without changes.
Binary file added Part Two/lenna_with_dragon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Part Two/wales-flag-xs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Part Two/wales.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
57 changes: 57 additions & 0 deletions clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## This is course material for Introduction to Python Scientific Programming
## Example code: matplotlib_clock.py
## Author: Allen Y. Yang
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use

from datetime import datetime
import matplotlib.pyplot as plt
import os
import numpy as np

# Initialization, define some constant
path = os.path.dirname(os.path.abspath(__file__))
filename = path + '/airplane.bmp'
background = plt.imread(filename)

second_hand_length = 200
second_hand_width = 2
minute_hand_length = 150
minute_hand_width = 6
hour_hand_length = 100
hour_hand_width = 10

center = np.array([256, 256])
def clock_hand_vector(angle, length):
return np.array([length * np.sin(angle), -length * np.cos(angle)])

# draw an image background
fig, ax = plt.subplots()
ax.set_axis_off()
while True:
plt.imshow(background)

# First retrieve the time
now_time = datetime.now()
hour = now_time.hour
if hour>12: hour = hour - 12
minute = now_time.minute
second = now_time.second

# Calculate end points of hour, minute, second
rps = second/60*2*np.pi
rpm = (minute + second / 60) / 60 * 2 * np.pi
rph = (hour + minute / 60 + second / 3600) / 12 * 2 * np.pi
rpgmth = hour + 7/ 24 * 2 * np.pi
hour_vector = clock_hand_vector(rph, hour_hand_length)
minute_vector = clock_hand_vector(rpm, minute_hand_length)
second_vector = clock_hand_vector(rps, second_hand_length)
gmt_vector = clock_hand_vector(rpgmth, second_hand_length)

plt.arrow(center[0], center[1], hour_vector[0], hour_vector[1], head_length = 3, linewidth = hour_hand_width, color = 'black')
plt.arrow(center[0], center[1], gmt_vector[0], gmt_vector[1], head_length = 3, linewidth = hour_hand_width, color = 'yellow')
plt.arrow(center[0], center[1], minute_vector[0], minute_vector[1], linewidth = minute_hand_width, color = 'black')
plt.arrow(center[0], center[1], second_vector[0], second_vector[1], linewidth = second_hand_width, color = 'red')

plt.pause(0.01)
plt.clf()
Empty file added graph.py
Empty file.
25 changes: 25 additions & 0 deletions learning_rates.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#.0001\n",
"#.01\n",
"#.5\n",
"\"\"\"if you choose a value too small you will take forever\"\"\"\n",
"\"\"\"if you choose a value too large you might go past the limits of the graph\"\"\"\n",
"\"\"\"even if you had infinite time and resources, you should still not choose too small of a value because of local minima.\"\"\""
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 1 addition & 2 deletions samples/read_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
plot_data = data.copy()
for width in range(512):
for height in range(10):
plot_data[height][width] = [255, 0, 0] # Alternatively plot_data[height][width][:] = [255, 0, 0]
plot_data[511-height][width] = [0,0,255]


# Write the modified images
image.imsave(path+'/'+'lenna-mod.jpg', plot_data)
Expand Down
4 changes: 2 additions & 2 deletions samples/widget_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

# Create two sliders
axcolor = 'lightgoldenrodyellow'
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor)
axamp = plt.axes([0.25, 0.15, 0.65, 0.03], facecolor=axcolor)
axfreq = plt.axes([0.25, 0.1, 0.65, 0.05], facecolor=axcolor)
axamp = plt.axes([0.25, 0.15, 0.65, 0.05], facecolor=axcolor)
sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0, valstep=delta_f)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0, valstep=delta_a)

Expand Down