1
$\begingroup$

Given a list containing $4^k$ elements, how do I create a "square" $\underbrace{4\times...\times4}_{k\text{-times}}$ tensor of rank $k$?

Intuitively, I would opt for the ArrayReshape function. However, I am unsure how to proceed given the variable number of the tensor rank.

In case of $k=2$, we would have

tensor = ArrayReshape[list, {4,4}]

How do I generalize this function to the case of some arbitrary rank $k$?

$\endgroup$
1
$\begingroup$

Try ConstantArray

k = 3;
tensor = ArrayReshape[list, ConstantArray[4, k]]
$\endgroup$
  • $\begingroup$ Yes, that works perfectly! Thank you so much $\endgroup$ – Bobby_Tables Aug 7 at 15:29

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.