Almost. I believe the way Andrew describes Matrices in the text is as a list of lists. vec[i] will be a number but matrix[i] will be a list. So your output is attempting to sum a number with a list and is throwing an error.
Try running the following:
def vec_Mat_Mult(Mat, Vec):
#Vec is a vector e.g. a list it will be a row vector with n rows
#Mat is a matrix e.g. a list of list matrix m x n
#Mat x Vec in m x 1 : (m x n) x (n x 1)
z = []
for i in range(len(Mat)): #loop over rows of matrix
assert (len(Vec) == len(Mat[i])) #the number of columns of Mat
#must match rows of Vec
wtd_sum = 0
for j in range(len(Vec)): #loop over columns of Matrix
wtd_sum += Mat[i][j]*Vec[j] #perform sum
z.append(wtd_sum)
return z
import numpy as np
vec = [1, 2, 20]
mat = [[1, 0, 0],
[0, 1, 1],
[1, 2, 1],
[0, 0, 1]]
result = vec_Mat_Mult(mat, vec)
result_2 = np.array(mat).dot(np.array(vec))
print(result)
print(result_2)
