Numpy Import

import numpy as np

Initialize matrix A and B

A = [[1, 2, 4], [5, 3, 2]]
B = [[1, 3, 4], [1, 1, 1]]

Show Matrix A

A
[[1, 2, 4], [5, 3, 2]]

Show Matrix B

B
[[1, 3, 4], [1, 1, 1]]

Convert Matrix A from List to Numpy Array

A_np = np.array(A)
A_np
array([[1, 2, 4],
       [5, 3, 2]])

Convert Matrix B from List to Numpy Array

B_np = np.array(B)
B_np
array([[1, 3, 4],
       [1, 1, 1]])

Initialize constant s

s = 2

See how element-wise addition works

add_AB = A_np + B_np
add_AB
array([[2, 5, 8],
       [6, 4, 3]])

See how element-wise subtraction works

sub_AB = A_np - B_np
sub_AB
array([[ 0, -1,  0],
       [ 4,  2,  1]])

See how scalar multiplication works

mult_As = A_np * s
mult_As
array([[ 2,  4,  8],
       [10,  6,  4]])

Divide A by s

div_As = A_np / s
div_As
array([[0.5, 1. , 2. ],
       [2.5, 1.5, 1. ]])

What happens if we have a Matrix + scalar?

add_As = A_np + s
add_As
array([[3, 4, 6],
       [7, 5, 4]])

Initialize a 3 by 2 matrix

C_np = np.array([[1, 2], [3, 4],[5, 6]])
C_np
array([[1, 2],
       [3, 4],
       [5, 6]])

Initialize a 2 by 1 matrix

D_np = np.array([1,2])
D_np
array([1, 2])

We expect a resulting matrix of (3 by 2)*(2 by 1) = (3 by 1)

mult_CD = C_np @ D_np
mult_CD
array([ 5, 11, 17])

Initialize vector v

v = np.array([[1],[1],[1]])
v
array([[1],
       [1],
       [1]])

Show Matrix A again

A_np
array([[1, 2, 4],
       [5, 3, 2]])

Multiply A * v

Av = A_np @ v
Av
array([[ 7],
       [10]])