6
$\begingroup$

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...


Array


$\endgroup$
1

1 Answer 1

6
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Ah, I found TableForm, but did not see the TableHeadings modifier. Thanks! $\endgroup$ Dec 22, 2014 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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