mirror of
https://github.com/Visualize-ML/Book4_Power-of-Matrix.git
synced 2026-05-11 00:49:34 +08:00
Add files via upload
This commit is contained in:
50
Book4_Ch06_Python_Codes/Bk4_Ch6_03.py
Normal file
50
Book4_Ch06_Python_Codes/Bk4_Ch6_03.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
###############
|
||||
# Authored by Weisheng Jiang
|
||||
# Book 4 | From Basic Arithmetic to Machine Learning
|
||||
# Published and copyrighted by Tsinghua University Press
|
||||
# Beijing, China, 2022
|
||||
###############
|
||||
|
||||
|
||||
# Bk4_Ch6_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')
|
||||
Reference in New Issue
Block a user