# Create Array from list of indices/values

Is there is a performat way to convert something like

{{0,0},a},{{0,1},c},{{1,0},d},{{1,1},e}


into

{{a,b},{c,d}}


The indices are not always orderes and the only solution I can think of is searching for the maximum indices, create a matrix filled with 0 and use map afterwards to modify the matrix. Is there is a better way?

Thank you, Martin

• I assume that when you write {{0,0},a},{{0,1},c},{{1,0},d},{{1,1},e} you actually mean {{{0, 0}, a}, {{0, 1}, b}, {{1, 0}, c}, {{1, 1}, d}}, Please check that the input is correct. Jul 17 '19 at 14:14

spec = {{{0, 0}, a}, {{0, 1}, b}, {{1, 0}, c}, {{1, 1}, d}};

Normal @ SparseArray[# + 1 -> #2 & @@@ spec]


{{a, b}, {c, d}}

Also possible:

r = {{{0, 0}, a}, {{0, 1}, c}, {{1, 0}, d}, {{1, 1}, e}};
SparseArray[r[[All, 1]] + 1 -> r[[All, 2]]]

(Array[{#1, #2} &, {2, 2}]-1)/.Rule@@@list


{{a, b}, {c, d}}

where

list={{{0, 0}, a}, {{0, 1}, b}, {{1, 0}, c}, {{1, 1}, d}};

• I think you misinterpret the question. The index may not be limited by 2. Jul 17 '19 at 18:05