# we may break lines when defining our list
M = [ 
    [8 , 0 , -1 , 0 , 2], 
    [-2 , -3 , 1 , 1 , 4], 
    [0 , 0 , 1 , -7 , 1],
    [1 , 4 , -2 , 5 , 9]
] 

# let's print matrix M
print(M)

# let's print M in matrix form, row by row

for i in range(4): # there are 4 rows
    print(M[i])

M = [ 
    [8 , 0 , -1 , 0 , 2], 
    [-2 , -3 , 1 , 1 , 4], 
    [0 , 0 , 1 , -7 , 1],
    [1 , 4 , -2 , 5 , 9]
] 

#let's print the element of M in the 1st row and the 1st column.
print(M[0][0])

#let's print the element of M in the 3rd row and the 4th column.
print(M[2][3])

#let's print the element of M in the 4th row and the 5th column.
print(M[3][4])

# we use double nested for-loops

N =[] # the result matrix

for i in range(4): # for each row
    N.append([]) # create an empty sub-list for each row in the result matrix
    for j in range(5): # in row (i+1), we do the following for each column
        N[i].append(M[i][j]*-2) # we add new elements into the i-th sub-list
        
# let's print M and N, and see the results
print("I am M:")
for i in range(4):
    print(M[i])

print()

print("I am N:")
for i in range(4):
    print(N[i])

# create an empty list for the result matrix
K=[]

for i in range(len(M)): # len(M) return the number of rows in M
    K.append([]) # we create a new row for K
    for j in range(len(M[0])): # len(M[0]) returns the number of columns in M
        K[i].append(M[i][j]+N[i][j]) # we add new elements into the i-th sublist/rows

# print each matrix in a single line
print("M=",M)
print("N=",N)
print("K=",K)

from random import randrange
#
# your solution is here
#


M = [
    [-2,3,0,4],
    [-1,1,5,9]      
]
N =[
    [1,2,3],
    [4,5,6],
    [7,8,9]
]
#
# your solution is here
#


# matrix M
M = [
    [-1,0,1],
    [-2,-3,4],
    [1,5,6]
]

# vector v
v = [1,-3,2]

# the result vector u
u = []

# for each row, we do an inner product
for i in range(3):
    # inner product for one row is initiated
    inner_result = 0 # this variable keeps the summation of the pairwise multiplications
    for j in range(3): # the elements in the i-th row
        inner_result = inner_result + M[i][j] * v[j]
    # inner product for one row is completed
    u.append(inner_result)

print("M is")
for i in range(len(M)):
    print(M[i])
print()
print("v=",v)
print()
print("u=",u)

#
# your solution is here
#


# matrix M
M = [
    [-1,0,1],
    [-2,-1,2],
    [1,2,-2]
]

# matrix N
M = [
    [0,2,1],
    [3,-1,-2],
    [-1,1,0]
]

# matrix K
K = []

#
# your solution is here
#


#
# your solution is here
#


