Specific list manipulationImplementing a function which generalizes the merging step in merge sortWhat is the...
Tikz/Pgf - Surf plot with smooth color transition
Rigorous justification for non-relativistic QM perturbation theory assumptions?
Is practicing on a digital piano harmful to an experienced piano player?
smartctl reports overall health test as passed but the tests failed?
Is it really OK to use "because of"?
"Starve to death" Vs. "Starve to the point of death"
Why is Shelob considered evil?
Is there a way to pause a running process on Linux systems and resume later?
What can I do to encourage my players to use their consumables?
Why might frozen potatoes require a hechsher?
Identical projects by students at two different colleges: still plagiarism?
Why do objects rebound after hitting the ground?
Buying a "Used" Router
Homeostasis logic/math problem
Calculating the strength of an ionic bond that contains poly-atomic ions
How do I avoid the "chosen hero" feeling?
How can I differentiate duration vs starting time
How can I handle players killing my NPC outside of combat?
Other than edits for international editions, did Harry Potter and the Philosopher's Stone receive errata?
Why is it that Bernie Sanders is always called a "socialist"?
How to not let the Identify spell spoil everything?
Do we still track damage on indestructible creatures?
Are all power cords made equal?
What is an efficient way to digitize a family photo collection?
Specific list manipulation
Implementing a function which generalizes the merging step in merge sortWhat is the correct way to conditionally add elements to lists?How to create a Table of Tables with indexed variablesDealing with a huge datasetThreading elements over corresponding elements in the second listPick the maximum element of each nested listFinding the most common n-tuples of a list of lists where order does not matterGet sublists by pattern?Can a simple Part expression produce a list of elements from nested lists?Interpolating and plotting from a list
$begingroup$
Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3}
and ListY = {y1,y2}
and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6}
of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1)
is associated with z1
, say.
How to merge all three lists such that I obtain the following combined list?
{{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}
I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).
list-manipulation table array
$endgroup$
add a comment |
$begingroup$
Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3}
and ListY = {y1,y2}
and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6}
of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1)
is associated with z1
, say.
How to merge all three lists such that I obtain the following combined list?
{{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}
I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).
list-manipulation table array
$endgroup$
add a comment |
$begingroup$
Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3}
and ListY = {y1,y2}
and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6}
of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1)
is associated with z1
, say.
How to merge all three lists such that I obtain the following combined list?
{{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}
I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).
list-manipulation table array
$endgroup$
Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3}
and ListY = {y1,y2}
and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6}
of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1)
is associated with z1
, say.
How to merge all three lists such that I obtain the following combined list?
{{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}
I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).
list-manipulation table array
list-manipulation table array
asked 3 hours ago
CAFCAF
255110
255110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
This seems to do what you are looking for:
ListX = {x1, x2, x3};
ListY = {y1, y2};
ListZ = {z1, z2, z3, z4, z5, z6};
Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]
The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.
$endgroup$
add a comment |
$begingroup$
Transpose@{Tuples@{ListX, ListY}, ListZ}
New contributor
$endgroup$
1
$begingroup$
Very nice solution! You can also useThread
instead ofTranspose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192128%2fspecific-list-manipulation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
This seems to do what you are looking for:
ListX = {x1, x2, x3};
ListY = {y1, y2};
ListZ = {z1, z2, z3, z4, z5, z6};
Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]
The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.
$endgroup$
add a comment |
$begingroup$
This seems to do what you are looking for:
ListX = {x1, x2, x3};
ListY = {y1, y2};
ListZ = {z1, z2, z3, z4, z5, z6};
Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]
The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.
$endgroup$
add a comment |
$begingroup$
This seems to do what you are looking for:
ListX = {x1, x2, x3};
ListY = {y1, y2};
ListZ = {z1, z2, z3, z4, z5, z6};
Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]
The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.
$endgroup$
This seems to do what you are looking for:
ListX = {x1, x2, x3};
ListY = {y1, y2};
ListZ = {z1, z2, z3, z4, z5, z6};
Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]
The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.
answered 3 hours ago
bill sbill s
53.6k376152
53.6k376152
add a comment |
add a comment |
$begingroup$
Transpose@{Tuples@{ListX, ListY}, ListZ}
New contributor
$endgroup$
1
$begingroup$
Very nice solution! You can also useThread
instead ofTranspose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
add a comment |
$begingroup$
Transpose@{Tuples@{ListX, ListY}, ListZ}
New contributor
$endgroup$
1
$begingroup$
Very nice solution! You can also useThread
instead ofTranspose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
add a comment |
$begingroup$
Transpose@{Tuples@{ListX, ListY}, ListZ}
New contributor
$endgroup$
Transpose@{Tuples@{ListX, ListY}, ListZ}
New contributor
New contributor
answered 3 hours ago
ukarukar
191
191
New contributor
New contributor
1
$begingroup$
Very nice solution! You can also useThread
instead ofTranspose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
add a comment |
1
$begingroup$
Very nice solution! You can also useThread
instead ofTranspose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
1
1
$begingroup$
Very nice solution! You can also use
Thread
instead of Transpose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Very nice solution! You can also use
Thread
instead of Transpose
:Thread@{Tuples@{ListX, ListY}, ListZ}
$endgroup$
– rmw
2 hours ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
$begingroup$
Yes. Thanks for reminding me that.
$endgroup$
– ukar
10 mins ago
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192128%2fspecific-list-manipulation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown