1
$\begingroup$

Consider some test table

tab=Table[{i,i^2},{i,1,100,1}];

I would like to obtain the table

tab2=Join[tab,tab,...,tab]

where ... include some number of tab, in a compact and smart way. Say, for 10 tab, the stupid way would be

tab2=Join[tab,tab,tab,tab,tab,tab,tab,tab,tab,tab]

Could you please tell me how to do this?

My guess is

tab[n_]:=Flatten[Table[tab2,{i,1,n,1}],1]

But I have doubts whether it will be fast in case of large tables.

$\endgroup$
6
  • 1
    $\begingroup$ To do this say 20 times, tab3 = Flatten[#, 1] &@Table[tab, 20]? $\endgroup$
    – Syed
    Sep 19, 2022 at 11:26
  • 2
    $\begingroup$ tab4 = Catenate[Table[tab, 20]] $\endgroup$
    – Syed
    Sep 19, 2022 at 11:29
  • 1
    $\begingroup$ tab5 = Fold[Join, ConstantArray[tab, 20]] $\endgroup$
    – Syed
    Sep 19, 2022 at 11:40
  • 1
    $\begingroup$ tab6 = Sequence @@@ ConstantArray[tab, 20] $\endgroup$
    – Syed
    Sep 19, 2022 at 11:44
  • $\begingroup$ Looks like a possible x-y problem. What is the actual goal? $\endgroup$
    – Alan
    Sep 19, 2022 at 13:15

1 Answer 1

5
$\begingroup$
tab2 == Join @@ ConstantArray[tab, 10]
(*    True    *)
$\endgroup$

Your Answer

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

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