If I have a list of the following form:

{1,1,1,0,1,1,1}

How can I create a list containing 5 of these lists ie:

{{1,1,1,0,1,1,1},{1,1,1,0,1,1,1},{1,1,1,0,1,1,1},{1,1,1,0,1,1,1},{1,1,1,0,1,1,1}}

put on hold as off-topic by C. E., Bob Hanlon, eyorble, Michael E2, Henrik Schumacher 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – C. E., Bob Hanlon, eyorble, Michael E2, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    e.g. ConstantArray[{1, 1, 1, 0, 1, 1, 1}, 5], Table would do the same thing. – C. E. Dec 8 at 19:41
  • Yep, was about to post that as an answer. Got me first. – Titus Dec 8 at 19:43
  • Ok for example, I want to generate 5 lists of random 0s and 1s, each of length 10: – beemen Dec 8 at 19:52
  • 2
    If the five are identical then ConstantArray[RandomInteger[1, 10], 5]; if each is random then RandomInteger[1, {5, 10}] – Bob Hanlon Dec 8 at 20:08

Besides ConstantArray and Table, one can use KroneckerProduct as well

vector = {1, 1, 1, 0, 1, 1, 1};
KroneckerProduct[{1, 1, 1, 1, 1}, vector]

Try this:

Table[a, 5] /. a :> {1, 1, 1, 0, 1, 1, 1}

(* {{1, 1, 1, 0, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 
  1}, {1, 1, 1, 0, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 1}}  *)

Have fun!

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