I solved it at first by generating a numpy grid then I went on to use dict and toolz.dicttoolz.merge_with