The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Y.G. Bae (36) [Avatar] Offline
#1
Hello.

In vect_mat_mul function in pg.41 of MEAP 11:
def vect_mat_mul(vect,matrix):
    assert(len(vect) == len(matrix))
    output = [0,0,0]
    for i in range(len(vect)):
        output[i] = w_sum(vect,matrix[i])
    return output


assert is comparing the length of the vector to the length of the matrix which actually is the number of the rows in the matrix. However, because the row in the matrix represents each prediction, shouldn't the length of inputs, the vector, be compared to the length of the weights per prediction, the number of the columns in the matrix, instead, something like the below?

def vect_mat_mul(vect,matrix):
    assert(len(vect) == len(matrix[0]))
    output = [0,0,0]
    for i in range(len(vect)):
        output[i] = w_sum(vect,matrix[i])
    return output


To me, it's like multiplying a 3 x 3 matrix to a 3 x 1 column vector, so comparing the number of the rows in the matrix to the number of rows in the column vector doesn't seem right. The number of columns in a matrix should match with the number of rows in a column vector to successfully multiply them together.