a = [[1, 5, 2], [4, 3, 2]] h = Hash[* a.transpose.flatten] puts h # {1 => 4, 5 => 3, 2 => 2}