import itertools
nested_loop_iter = itertools.product(n_vocab, m_vocab)
probs = np.fromiter(map(hashes.get, nested_loop_iter), dtype=float)
probs.resize((len(n_vocab), len(m_vocab)))
probs = probs.T
Creating a |N| x |M| matrix from a hash-table