My clean python solution using Lambda function and map

  • 0

    The idea is simple, a vector multiply a matrix is to sum the vector components with weights. Here is a link

    class Solution(object):
        def multiply(self, A, B):
            :type A: List[List[int]]
            :type B: List[List[int]]
            :rtype: List[List[int]]
            ans = []
            for arr in A:
                line = [0] * len(B[0])
                for i in xrange(len(arr)):
                    if arr[i] != 0:
                        line = map(sum, zip(line, map(lambda y: arr[i]*y, B[i])))
            return ans

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.