6
$\begingroup$

i want to obtain this definition of a nested list

t = Table[C[i, j], {i, 3}, {j, 3}]

with arbitrary depth,

t = Table[C[i, j ... p,q], {i, 3}, {j, 3} ... {p, 3}, {q, 3}]

I have tried Nest like so,

Nest[Table[#1, {t, 3}] &, C, 2]

but do not manage to get the indices into the element as in C[i, j, ...].

$\endgroup$
  • 1
    $\begingroup$ You could use Outer[C, Range[4], Range[5], Range[3]]. $\endgroup$ – b.gates.you.know.what Jun 10 at 7:17
7
$\begingroup$

You can try Array:

Array[c, {3, 3, 3, 3}]

enter image description here

arraydepth = 3;
Array[c, ConstantArray[3, arraydepth]]

enter image description here

| improve this answer | |
$\endgroup$
3
$\begingroup$

To elaborate on b.gates.you.know.what's comment, this is a scalable version equivalent to kglr's solution:

Outer[c, Sequence @@ ConstantArray[{1, 2, 3}, 4]] === Array[c, {3, 3, 3, 3}]

True

{1, 2, 3} can be a list of any elements.

| improve this answer | |
$\endgroup$

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.