Search code examples
pythonmatrixmatrix-multiplication

Multiplication of matrices stored in lists


I am struggling to multiply lists as matrices in Python.

I have two lists (weights and returns) and I need to multiply them as: weights*TRANSPOSE(returns).

Example


Solution

  • How are Weights and Return defined in your code? You might be able to do the following:

    #This sums the entries
    matrixProduct = 0
    for i in range(len(Weights)):
        matrixProduct+= Weights[i]*Return[i]
    
    #In case you meant to keep products of individual pairs of matrix entries (not sure from your notation):
    matrixProduct = []
    for i in range(len(Weights)):
        matrixProduct.append(Weights[i]*Return[i])