Message Boards Message Boards

0
|
3946 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to create multiple copies of a list

Posted 11 years ago
I'm a newbie and am trying to make multiple copies of a list.  For example, if I have the list {1,2,3}, I'd like to do something like
2*{{1,2,3}}
and get
{{1,2,3},{1,2,3}}
I'm looking for functionality similar to this in python:
>>> 2*[[1,2,3]]
[[1, 2, 3], [1, 2, 3]]
Thanks!
POSTED BY: Betty Love
2 Replies
Posted 11 years ago
Thank you!
POSTED BY: Betty Love
Posted 11 years ago
ConstantArray should do the trick, and not just for lists but for any expression.

ConstantArray[{1, 2, 3}, 2]

(* Out: {{1, 2, 3}, {1, 2, 3}} *)

http://reference.wolfram.com/mathematica/ref/ConstantArray.html
POSTED BY: William Rummler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract