Group Abstract Group Abstract

Message Boards Message Boards

2
|
3.9K Views
|
4 Replies
|
11 Total Likes
View groups...
Share
Share this post:

List manipulation: subsets from a ragged array

Suppose I have the following list:

originalList = {{a},{b,c},{d,e,f}}

Now, I want to create a new list such that each element of this new list is also list containing 3 elements. Each of this 3 elements comes from different subsets of the originalList. In other words, how do I create the following list:

{{a,b,d},{a,b,e},{a,b,f},{a,c,d},{a,c,e},{a,c,f}}

Thanks in advance.

POSTED BY: Diogo Duarte
4 Replies

Though Outer is definitely possible, I would definitely used Tuples in this case!

originalList = {{a}, {b, c}, {d, e, f}}
Tuples[originalList]

much much easier!

POSTED BY: Sander Huisman

Yes, this is neat!

POSTED BY: Vitaliy Kaurov

Also note that Tuples will generally be faster than Outer for this operation. Generally Outer is kinda slow because it generally(always?) does not vectorizes calculations... which is sometimes possible...

POSTED BY: Sander Huisman

Sounds like Outer:

originalList = {{a}, {b, c}, {d, e, f}};
Flatten[Outer[List, Sequence @@ originalList], 2]
Out[]= {{a, b, d}, {a, b, e}, {a, b, f}, {a, c, d}, {a, c, e}, {a, c, f}}
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard