Question

Hey so I was just wondering how to compute the the dotproduct of two matrices using a user defined function.

For example:

row(C,0)=[4, 1, 9]
col(D,0)=[2, 5, 1]
def dotProduct(x,y):


print(dotProduct(row(C,0), col(D,0)))

Should result in 22

Était-ce utile?

La solution

def dotProduct(x,y):
    prod=0
    for i in range(len(x)):
        prod=prod+x[i]*y[i]
    return prod
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top