Is there a single function that prints an array together with the indices? I know how to achieve this with Grid[{Range[n],array},Frame->All], but I vaguely recall there is a special function that achieves this? I am not finding it via searches...



TableForm does the trick:

array = {{"a", "b", "c", "d"}};

TableForm[array, TableHeadings -> {None, Automatic}]

Mathematica graphics

More flexible would be a MapIndexed-based solution:

Grid[MapIndexed[{#2[[1]], #} &, array[[1]]] // Transpose, 
 Frame -> All]

Mathematica graphics

  • $\begingroup$ Ah, I found TableForm, but did not see the TableHeadings modifier. Thanks! $\endgroup$ – Joseph O'Rourke Dec 22 '14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.