Question

in python def matrixMultiplication(matrix, vector):     """Return the product of a matrix and a vector    ...

in python

def matrixMultiplication(matrix, vector):
    """Return the product of a matrix and a vector

    Arguments:
        matrix: A list of lists representing an nxn matrix
        vector: A list representing an nx1 matrix

    Returns:
        A list representing the nx1 matrix obtained by multiplying the input
        matrix by the input vector.

    >>> matrix = [[1, 2, 3], [2, 3, 1], [4, 1, 2]]
    >>> vector = [1, 2, 3]
    >>> matrixMultiplication(matrix, vector)
    [14, 11, 11]
    """

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def matrixMultiplication(matrix, vector):
    """Return the product of a matrix and a vector

    Arguments:
        matrix: A list of lists representing an nxn matrix
        vector: A list representing an nx1 matrix

    Returns:
        A list representing the nx1 matrix obtained by multiplying the input
        matrix by the input vector.

    >>> matrix = [[1, 2, 3], [2, 3, 1], [4, 1, 2]]
    >>> vector = [1, 2, 3]
    >>> matrixMultiplication(matrix, vector)
    [14, 11, 11]
    """
    lst = []
    for i in range(len(matrix)):
        total = 0
        for k in range(len(vector)):
            total += matrix[i][k] * vector[k]
        lst.append(total)
    return lst


matrix = [[1, 2, 3], [2, 3, 1], [4, 1, 2]]
vector = [1, 2, 3]
print(matrixMultiplication(matrix, vector))
Add a comment
Know the answer?
Add Answer to:
in python def matrixMultiplication(matrix, vector):     """Return the product of a matrix and a vector    ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT