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:
41
Book4_Ch04_Python_Codes/Bk4_Ch4_05.py
Normal file
41
Book4_Ch04_Python_Codes/Bk4_Ch4_05.py
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
###############
|
||||
# Authored by Weisheng Jiang
|
||||
# Book 4 | From Basic Arithmetic to Machine Learning
|
||||
# Published and copyrighted by Tsinghua University Press
|
||||
# Beijing, China, 2022
|
||||
###############
|
||||
|
||||
# Bk4_Ch4_05.py
|
||||
|
||||
import numpy as np
|
||||
|
||||
# define matrix
|
||||
A = np.matrix([[1, 2],
|
||||
[3, 4],
|
||||
[5, 6]])
|
||||
|
||||
# scaler
|
||||
k = 2;
|
||||
|
||||
# column vector c
|
||||
c = np.array([[3],
|
||||
[2],
|
||||
[1]])
|
||||
|
||||
# row vector r
|
||||
r = np.array([[2,1]])
|
||||
|
||||
# broadcasting principles
|
||||
|
||||
# matrix A plus scalar k
|
||||
A_plus_k = A + k
|
||||
|
||||
# matrix A plus column vector c
|
||||
A_plus_a = A + c
|
||||
|
||||
# matrix A plus row vector r
|
||||
A_plus_r = A + r
|
||||
|
||||
# column vector c plus row vector r
|
||||
c_plus_r = c + r
|
||||
Reference in New Issue
Block a user