From bb1b67a73bef5b867598fec9abedf94042900bcc Mon Sep 17 00:00:00 2001 From: Visualize-ML <105787223+Visualize-ML@users.noreply.github.com> Date: Fri, 15 Jul 2022 06:05:53 -0400 Subject: [PATCH] Delete Book4_Ch05_Python_Codes directory --- Book4_Ch05_Python_Codes/Bk4_Ch5_01.py | 33 ---------------- Book4_Ch05_Python_Codes/Bk4_Ch5_02.py | 54 --------------------------- Book4_Ch05_Python_Codes/Bk4_Ch5_03.py | 50 ------------------------- 3 files changed, 137 deletions(-) delete mode 100644 Book4_Ch05_Python_Codes/Bk4_Ch5_01.py delete mode 100644 Book4_Ch05_Python_Codes/Bk4_Ch5_02.py delete mode 100644 Book4_Ch05_Python_Codes/Bk4_Ch5_03.py diff --git a/Book4_Ch05_Python_Codes/Bk4_Ch5_01.py b/Book4_Ch05_Python_Codes/Bk4_Ch5_01.py deleted file mode 100644 index b910290..0000000 --- a/Book4_Ch05_Python_Codes/Bk4_Ch5_01.py +++ /dev/null @@ -1,33 +0,0 @@ - -############### -# Authored by Weisheng Jiang -# Book 4 | From Basic Arithmetic to Machine Learning -# Published and copyrighted by Tsinghua University Press -# Beijing, China, 2022 -############### - - -# Bk4_Ch5_01.py - -import numpy as np - -A = np.array([[1, 2, 3, 0, 0], - [4, 5, 6, 0, 0], - [0, 0, 0, -1, 0], - [0, 0 ,0, 0, 1]]) - -# NumPy array slicing - -A_1_1 = A[0:2,0:3] - -A_1_2 = A[0:2,3:] -# A_1_2 = A[0:2,-2:] -A_2_1 = A[2:,0:3] -# A_2_1 = A[-2:,0:3] -A_2_2 = A[2:,3:] -# A_2_2 = A[-2:,-2:] - -# Assemble a matrix from nested lists of blocks - -A_ = np.block([[A_1_1, A_1_2], - [A_2_1, A_2_2]]) diff --git a/Book4_Ch05_Python_Codes/Bk4_Ch5_02.py b/Book4_Ch05_Python_Codes/Bk4_Ch5_02.py deleted file mode 100644 index 193cfb5..0000000 --- a/Book4_Ch05_Python_Codes/Bk4_Ch5_02.py +++ /dev/null @@ -1,54 +0,0 @@ - -############### -# Authored by Weisheng Jiang -# Book 4 | From Basic Arithmetic to Machine Learning -# Published and copyrighted by Tsinghua University Press -# Beijing, China, 2022 -############### - - -# Bk4_Ch5_02.py - -import matplotlib.pyplot as plt -import numpy as np -import seaborn as sns - -def plot_heatmap(x,title): - - fig, ax = plt.subplots() - ax = sns.heatmap(x, - cmap='RdYlBu_r', - cbar_kws={"orientation": "horizontal"}, vmin=-1, vmax=1) - ax.set_aspect("equal") - plt.title(title) - -# Generate matrices A and B -A = np.random.random_integers(0,40,size=(6,4)) -A = A/20 - 1 - -B = np.random.random_integers(0,40,size=(4,3)) -B = B/20 - 1 - -# visualize matrix A and B -plot_heatmap(A,'A') - -plot_heatmap(B,'B') - -# visualize A@B -C = A@B -plot_heatmap(C,'C = AB') - -C_rep = np.zeros_like(C) - -# reproduce C - -for i in np.arange(4): - C_i = A[:,[i]]@B[[i],:]; - title = 'C' + str(i + 1) - plot_heatmap(C_i,title) - - C_rep = C_rep + C_i - -# Visualize reproduced C -plot_heatmap(C_rep,'C reproduced') - diff --git a/Book4_Ch05_Python_Codes/Bk4_Ch5_03.py b/Book4_Ch05_Python_Codes/Bk4_Ch5_03.py deleted file mode 100644 index 5d27b39..0000000 --- a/Book4_Ch05_Python_Codes/Bk4_Ch5_03.py +++ /dev/null @@ -1,50 +0,0 @@ - -############### -# Authored by Weisheng Jiang -# Book 4 | From Basic Arithmetic to Machine Learning -# Published and copyrighted by Tsinghua University Press -# Beijing, China, 2022 -############### - - -# Bk4_Ch5_03.py - -import numpy as np -from matplotlib import pyplot as plt -import seaborn as sns - -A = np.array([[-1, 1], - [0.7, -0.4]]) - -B = np.array([[0.5, -0.6], - [-0.8, 0.3]]) - -A_kron_B = np.kron(A, B) - -fig, axs = plt.subplots(1, 5, figsize=(12, 5)) - -plt.sca(axs[0]) -ax = sns.heatmap(A,cmap='RdYlBu_r',vmax = 1,vmin = -1, - cbar_kws={"orientation": "horizontal"}) -ax.set_aspect("equal") -plt.title('A') - -plt.sca(axs[1]) -plt.title('$\otimes$') -plt.axis('off') - -plt.sca(axs[2]) -ax = sns.heatmap(B,cmap='RdYlBu_r',vmax = 1,vmin = -1, - cbar_kws={"orientation": "horizontal"}) -ax.set_aspect("equal") -plt.title('B') - -plt.sca(axs[3]) -plt.title('=') -plt.axis('off') - -plt.sca(axs[4]) -ax = sns.heatmap(A_kron_B,cmap='RdYlBu_r',vmax = 1,vmin = -1, - cbar_kws={"orientation": "horizontal"}) -ax.set_aspect("equal") -plt.title('C')