We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Map Reduce Advanced - Matrix Multiplication
Map Reduce Advanced - Matrix Multiplication
Sort by
recency
|
14 Discussions
|
Please Login in order to post a comment
Another simple solution:
Here is Map Reduce Advanced - Matrix Multiplication problem solution - https://www.gyangav.com/2022/11/hackerrank-map-reduce-advanced-matrix-multiplication-problem-solution.html
!/usr/bin/env python2.7
from collections import OrderedDict import itertools import sys
class MapReduce: def init(self): self.intermediate = OrderedDict() self.result = []
mapReducer = None
def mapper(matrix1, matrix2): #Start writing the Map code here n = len(matrix1) k = len(matrix1[0]) m = len(matrix2[0])
def reducer(key, list_of_values): #Start writing the Reduce code here mapReducer.emit((key[0], key[1], sum(itertools.starmap(lambda x, y: x * y, list_of_values))))
if name == 'main': testcases = int(sys.stdin.readline().strip()) for t in xrange(0,testcases): mapReducer = MapReduce() dimensions = sys.stdin.readline().strip().split(" ") row = int(dimensions[0]) column = int(dimensions[1]) matrix1 = [] matrix2 = [] for i in range(0, row): read_row = sys.stdin.readline().strip() matrix1.append([]) row_elems = read_row.strip().split() for j in range(0, len(row_elems)): matrix1[i].append(int(row_elems[j])) dimensions = sys.stdin.readline().strip().split(" ") row = int(dimensions[0]) column = int(dimensions[1]) for i in range(0, row): read_row = sys.stdin.readline().strip() matrix2.append([]) row_elems = read_row.strip().split() for j in range(0, len(row_elems)): matrix2[i].append(int(row_elems[j])) mapReducer.execute(matrix1, matrix2, mapper, reducer)
Good information! I have no idea about it! strong relationship dua for husband and wife