Group Abstract Group Abstract

Message Boards Message Boards

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

List manipulation: subsets from a ragged array

POSTED BY: Diogo Duarte
4 Replies

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

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

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

Yes, this is neat!

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