class AddMatricesFn(beam.DoFn):
   def process(self, element, *args, **kwargs):
      index, cogroupby = element
      firstmatrix = cogroupby['firstmatrix'][0]
      secondmatrix = cogroupby['secondmatrix'][0]
      summatrix = firstmatrix + secondmatrix
      yield index, summatrix