Converting dictionaries to a matrix