Apply MapThread to all but one variableHow do you efficiently return all of a List but one element?All values for a function with two arguments without OuterEfficiently finding the maximum value of a column in a matrixnested use of Apply/Map/MapThread in pure functionsMapThread AlternativesFinding neighbors from listMapThread problemapply binary operation to all adjacent pairsFlip sign of one variable in listFind numbers from Mean, Variance and Correlation coefficient
Is the claim "Employers won't employ people with no 'social media presence'" realistic?
What is the smallest unit of eos?
Is there any official lore on the Far Realm?
Was there a shared-world project before "Thieves World"?
Mistake in years of experience in resume?
Apply MapThread to all but one variable
Overlay of two functions leaves gaps
Can I criticise the more senior developers around me for not writing clean code?
How exactly does Hawking radiation decrease the mass of black holes?
What makes accurate emulation of old systems a difficult task?
How can I practically buy stocks?
Multiple options vs single option UI
Checks user level and limit the data before saving it to mongoDB
Does a large simulator bay have standard public address announcements?
Do I have an "anti-research" personality?
Minor Revision with suggestion of an alternative proof by reviewer
Don’t seats that recline flat defeat the purpose of having seatbelts?
Is there really no use for MD5 anymore?
Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?
Why did some of my point & shoot film photos come back with one third light white or orange?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Function pointer with named arguments?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Is it idiomatic to construct against `this`
Apply MapThread to all but one variable
How do you efficiently return all of a List but one element?All values for a function with two arguments without OuterEfficiently finding the maximum value of a column in a matrixnested use of Apply/Map/MapThread in pure functionsMapThread AlternativesFinding neighbors from listMapThread problemapply binary operation to all adjacent pairsFlip sign of one variable in listFind numbers from Mean, Variance and Correlation coefficient
$begingroup$
I would like to know what is the most efficient to implement the following computation. Given three lists
a = a_1,a_2, a_3, …, a_n
b = b_1,b_2, b_3, …, b_n
c = c_1,c_2, c_3, …, c_n
and a function $f(x_1,x_2,x_3)$, obtain
f(a_1,b_1,c_1) f(a_1,b_1,c_2) ..... f(a_1,b_1,c_n)
f(a_2,b_2,c_1) f(a_2,b_2,c_2) ..... f(a_2,b_2,c_n)
..... ..... ..... .....
f(a_n,b_n,c_1) f(a_n,b_n,c_2) ..... f(a_n,b_n,c_n)
I cannot find a solution not using For.
list-manipulation
$endgroup$
add a comment |
$begingroup$
I would like to know what is the most efficient to implement the following computation. Given three lists
a = a_1,a_2, a_3, …, a_n
b = b_1,b_2, b_3, …, b_n
c = c_1,c_2, c_3, …, c_n
and a function $f(x_1,x_2,x_3)$, obtain
f(a_1,b_1,c_1) f(a_1,b_1,c_2) ..... f(a_1,b_1,c_n)
f(a_2,b_2,c_1) f(a_2,b_2,c_2) ..... f(a_2,b_2,c_n)
..... ..... ..... .....
f(a_n,b_n,c_1) f(a_n,b_n,c_2) ..... f(a_n,b_n,c_n)
I cannot find a solution not using For.
list-manipulation
$endgroup$
add a comment |
$begingroup$
I would like to know what is the most efficient to implement the following computation. Given three lists
a = a_1,a_2, a_3, …, a_n
b = b_1,b_2, b_3, …, b_n
c = c_1,c_2, c_3, …, c_n
and a function $f(x_1,x_2,x_3)$, obtain
f(a_1,b_1,c_1) f(a_1,b_1,c_2) ..... f(a_1,b_1,c_n)
f(a_2,b_2,c_1) f(a_2,b_2,c_2) ..... f(a_2,b_2,c_n)
..... ..... ..... .....
f(a_n,b_n,c_1) f(a_n,b_n,c_2) ..... f(a_n,b_n,c_n)
I cannot find a solution not using For.
list-manipulation
$endgroup$
I would like to know what is the most efficient to implement the following computation. Given three lists
a = a_1,a_2, a_3, …, a_n
b = b_1,b_2, b_3, …, b_n
c = c_1,c_2, c_3, …, c_n
and a function $f(x_1,x_2,x_3)$, obtain
f(a_1,b_1,c_1) f(a_1,b_1,c_2) ..... f(a_1,b_1,c_n)
f(a_2,b_2,c_1) f(a_2,b_2,c_2) ..... f(a_2,b_2,c_n)
..... ..... ..... .....
f(a_n,b_n,c_1) f(a_n,b_n,c_2) ..... f(a_n,b_n,c_n)
I cannot find a solution not using For.
list-manipulation
list-manipulation
edited 2 hours ago
corey979
20.9k64382
20.9k64382
asked 2 hours ago
SmerdjakovSmerdjakov
1305
1305
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Here's one way to do it with Outer:
n = 3;
l1 = Array[a, n];
l2 = Array[b, n];
l3 = Array[c, n];
Outer[
f[#1[[1]], #1[[2]], #2] &,
Transpose @ l1, l2,
l3,
1
]
Out[25]= f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
1
$begingroup$
OrOuter[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1]so you don't need to unravel#1manually.
$endgroup$
– Roman
2 hours ago
add a comment |
$begingroup$
a = a1, a2, a3, a4, a5;
b = b1, b2, b3, b4, b5;
c = c1, c2, c3, c4, c5;
Table[f[a[[j]], b[[j]], c[[k]]], j, 1, 5, k, 1, 5]

$endgroup$
add a comment |
$begingroup$
Another possibility is to use the 3-arg version of Thread. With Sjoerd's example:
n = 3;
l1 = Array[a,n];
l2 = Array[b,n];
l3 = Array[c,n];
Using Thread:
Thread /@ Thread[f[l1, l2, l3], List, 2]
f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
add a comment |
Your Answer
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%2f197144%2fapply-mapthread-to-all-but-one-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Here's one way to do it with Outer:
n = 3;
l1 = Array[a, n];
l2 = Array[b, n];
l3 = Array[c, n];
Outer[
f[#1[[1]], #1[[2]], #2] &,
Transpose @ l1, l2,
l3,
1
]
Out[25]= f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
1
$begingroup$
OrOuter[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1]so you don't need to unravel#1manually.
$endgroup$
– Roman
2 hours ago
add a comment |
$begingroup$
Here's one way to do it with Outer:
n = 3;
l1 = Array[a, n];
l2 = Array[b, n];
l3 = Array[c, n];
Outer[
f[#1[[1]], #1[[2]], #2] &,
Transpose @ l1, l2,
l3,
1
]
Out[25]= f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
1
$begingroup$
OrOuter[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1]so you don't need to unravel#1manually.
$endgroup$
– Roman
2 hours ago
add a comment |
$begingroup$
Here's one way to do it with Outer:
n = 3;
l1 = Array[a, n];
l2 = Array[b, n];
l3 = Array[c, n];
Outer[
f[#1[[1]], #1[[2]], #2] &,
Transpose @ l1, l2,
l3,
1
]
Out[25]= f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
Here's one way to do it with Outer:
n = 3;
l1 = Array[a, n];
l2 = Array[b, n];
l3 = Array[c, n];
Outer[
f[#1[[1]], #1[[2]], #2] &,
Transpose @ l1, l2,
l3,
1
]
Out[25]= f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
answered 2 hours ago
Sjoerd SmitSjoerd Smit
4,610817
4,610817
1
$begingroup$
OrOuter[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1]so you don't need to unravel#1manually.
$endgroup$
– Roman
2 hours ago
add a comment |
1
$begingroup$
OrOuter[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1]so you don't need to unravel#1manually.
$endgroup$
– Roman
2 hours ago
1
1
$begingroup$
Or
Outer[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1] so you don't need to unravel #1 manually.$endgroup$
– Roman
2 hours ago
$begingroup$
Or
Outer[f[Sequence @@ #1, #2] &, Transpose@l1, l2, l3, 1] so you don't need to unravel #1 manually.$endgroup$
– Roman
2 hours ago
add a comment |
$begingroup$
a = a1, a2, a3, a4, a5;
b = b1, b2, b3, b4, b5;
c = c1, c2, c3, c4, c5;
Table[f[a[[j]], b[[j]], c[[k]]], j, 1, 5, k, 1, 5]

$endgroup$
add a comment |
$begingroup$
a = a1, a2, a3, a4, a5;
b = b1, b2, b3, b4, b5;
c = c1, c2, c3, c4, c5;
Table[f[a[[j]], b[[j]], c[[k]]], j, 1, 5, k, 1, 5]

$endgroup$
add a comment |
$begingroup$
a = a1, a2, a3, a4, a5;
b = b1, b2, b3, b4, b5;
c = c1, c2, c3, c4, c5;
Table[f[a[[j]], b[[j]], c[[k]]], j, 1, 5, k, 1, 5]

$endgroup$
a = a1, a2, a3, a4, a5;
b = b1, b2, b3, b4, b5;
c = c1, c2, c3, c4, c5;
Table[f[a[[j]], b[[j]], c[[k]]], j, 1, 5, k, 1, 5]

answered 2 hours ago
corey979corey979
20.9k64382
20.9k64382
add a comment |
add a comment |
$begingroup$
Another possibility is to use the 3-arg version of Thread. With Sjoerd's example:
n = 3;
l1 = Array[a,n];
l2 = Array[b,n];
l3 = Array[c,n];
Using Thread:
Thread /@ Thread[f[l1, l2, l3], List, 2]
f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
add a comment |
$begingroup$
Another possibility is to use the 3-arg version of Thread. With Sjoerd's example:
n = 3;
l1 = Array[a,n];
l2 = Array[b,n];
l3 = Array[c,n];
Using Thread:
Thread /@ Thread[f[l1, l2, l3], List, 2]
f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
add a comment |
$begingroup$
Another possibility is to use the 3-arg version of Thread. With Sjoerd's example:
n = 3;
l1 = Array[a,n];
l2 = Array[b,n];
l3 = Array[c,n];
Using Thread:
Thread /@ Thread[f[l1, l2, l3], List, 2]
f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
$endgroup$
Another possibility is to use the 3-arg version of Thread. With Sjoerd's example:
n = 3;
l1 = Array[a,n];
l2 = Array[b,n];
l3 = Array[c,n];
Using Thread:
Thread /@ Thread[f[l1, l2, l3], List, 2]
f[a[1], b[1], c[1]], f[a[1], b[1], c[2]],
f[a[1], b[1], c[3]], f[a[2], b[2], c[1]], f[a[2], b[2], c[2]],
f[a[2], b[2], c[3]], f[a[3], b[3], c[1]], f[a[3], b[3], c[2]],
f[a[3], b[3], c[3]]
answered 1 hour ago
Carl WollCarl Woll
75.9k3100198
75.9k3100198
add a comment |
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%2f197144%2fapply-mapthread-to-all-but-one-variable%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