mirror of
https://github.com/Visualize-ML/Book4_Power-of-Matrix.git
synced 2026-02-03 18:43:34 +08:00
23 lines
533 B
Python
23 lines
533 B
Python
|
|
###############
|
|
# Authored by Weisheng Jiang
|
|
# Book 4 | From Basic Arithmetic to Machine Learning
|
|
# Published and copyrighted by Tsinghua University Press
|
|
# Beijing, China, 2022
|
|
###############
|
|
|
|
# Bk4_Ch2_04.py
|
|
|
|
import numpy as np
|
|
|
|
a, b = np.array([[4], [3]]), np.array([[5], [-2]])
|
|
|
|
# calculate cosine theta
|
|
cos_theta = (a.T @ b) / (np.linalg.norm(a,2) * np.linalg.norm(b,2))
|
|
|
|
# calculate theta in radian
|
|
cos_radian = np.arccos(cos_theta)
|
|
|
|
# convert radian to degree
|
|
cos_degree = cos_radian * ((180)/np.pi)
|