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
  • 1
    $\begingroup$ You could use Outer[C, Range[4], Range[5], Range[3]]. $\endgroup$ Commented Jun 10, 2020 at 7:17

2 Answers 2

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

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

$\endgroup$

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.