Efficient way to sum over an index repeated more than twiceIs there a clean way to extract the subspaces invariant under a list of matrices?How to distribute PermutationProduct over the sumFinding an Integer, Unimodular Matrix that connects two given matricesSums of Solutions of a Linear SystemMaking a notebook with Taylor series of the square root of a determinant more efficientFast algorithm for finding all solutions of simple equation involving only addition of terms from listSolving underdetermined Lyapunov equations?
How likely are you to be injured by falling shot from a game shoot?
Were mixed race kids theorized to look like zebras?
How should chips with pins on bottom be drawn?
How should I conceal gaps between laminate flooring and wall trim?
Totally Blind Chess
Do any Star Trek characters play rock band instruments?
Trying to find a short story about the representative of a city discovering the "primitive" folk are actually more advanced
What does "T.O." mean?
How to Keep Winged People Where They Belong?
What are valid bugs
Fast symmetric key cryptography class
Is (manual) feature extraction outdated?
What potential problems are there with dumping dex in bard build?
What does it take to make metal music?
Why is Google's quantum supremacy experiment impressive?
Why is the air inside airliners so dry (low humidity)?
Is a turbocharged piston aircraft the same thing as turboprop?
Players who play fast in longer time control games
Can the Wish spell be used to allow someone to be able to cast all of their spells at will?
How to generate the following m-level n-particle state?
What are the reasons OR industry projects fail?
Starting Point ??
How time is defined in astronomical science
Tic Tac Toe console program
Efficient way to sum over an index repeated more than twice
Is there a clean way to extract the subspaces invariant under a list of matrices?How to distribute PermutationProduct over the sumFinding an Integer, Unimodular Matrix that connects two given matricesSums of Solutions of a Linear SystemMaking a notebook with Taylor series of the square root of a determinant more efficientFast algorithm for finding all solutions of simple equation involving only addition of terms from listSolving underdetermined Lyapunov equations?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;
$begingroup$
I'm looking for an efficient way of computing sums of the type
$$D_jk = sum_i=1^n A_ij B_ik C_i$$
for large numerical matrices $A$, $B$ and $C$.
Here is a slow solution:
DD = Table[Sum[AA[[i, j]] BB[[i, k]] CC[[i]], i, 1, n], j, 1, m, k, 1, m]
What's a fast way of doing it?
linear-algebra
$endgroup$
add a comment
|
$begingroup$
I'm looking for an efficient way of computing sums of the type
$$D_jk = sum_i=1^n A_ij B_ik C_i$$
for large numerical matrices $A$, $B$ and $C$.
Here is a slow solution:
DD = Table[Sum[AA[[i, j]] BB[[i, k]] CC[[i]], i, 1, n], j, 1, m, k, 1, m]
What's a fast way of doing it?
linear-algebra
$endgroup$
add a comment
|
$begingroup$
I'm looking for an efficient way of computing sums of the type
$$D_jk = sum_i=1^n A_ij B_ik C_i$$
for large numerical matrices $A$, $B$ and $C$.
Here is a slow solution:
DD = Table[Sum[AA[[i, j]] BB[[i, k]] CC[[i]], i, 1, n], j, 1, m, k, 1, m]
What's a fast way of doing it?
linear-algebra
$endgroup$
I'm looking for an efficient way of computing sums of the type
$$D_jk = sum_i=1^n A_ij B_ik C_i$$
for large numerical matrices $A$, $B$ and $C$.
Here is a slow solution:
DD = Table[Sum[AA[[i, j]] BB[[i, k]] CC[[i]], i, 1, n], j, 1, m, k, 1, m]
What's a fast way of doing it?
linear-algebra
linear-algebra
edited Jun 16 at 5:31
arne
asked Jun 16 at 3:12
arnearne
1285 bronze badges
1285 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
$begingroup$
n = 4;
m = 3;
aa = Array[a, n, m];
bb = Array[b, n, m];
cc = Array[c, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m];
You can Transpose aa and Dot it with bb cc:
Transpose[aa].(bb cc) == dd
True
Alternatively, you can Transpose aa cc and Dot it with bb:
Transpose[aa cc].bb ==dd
True
Comparison with Table/Sum combination:
SeedRandom[1]
n = 100;
m = 50;
aa = RandomReal[1, n, m];
bb = RandomReal[1, n, m];
cc = RandomReal[1, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m]; //
RepeatedTiming // First
0.417
ee1 = Transpose[aa].( bb cc) ; // RepeatedTiming // First
0.000051
ee2 = Transpose[aa cc].bb ; // RepeatedTiming // First
0.000045
dd == ee1 == ee2
True
$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/4.0/"u003ecc by-sa 4.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%2f200432%2fefficient-way-to-sum-over-an-index-repeated-more-than-twice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
n = 4;
m = 3;
aa = Array[a, n, m];
bb = Array[b, n, m];
cc = Array[c, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m];
You can Transpose aa and Dot it with bb cc:
Transpose[aa].(bb cc) == dd
True
Alternatively, you can Transpose aa cc and Dot it with bb:
Transpose[aa cc].bb ==dd
True
Comparison with Table/Sum combination:
SeedRandom[1]
n = 100;
m = 50;
aa = RandomReal[1, n, m];
bb = RandomReal[1, n, m];
cc = RandomReal[1, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m]; //
RepeatedTiming // First
0.417
ee1 = Transpose[aa].( bb cc) ; // RepeatedTiming // First
0.000051
ee2 = Transpose[aa cc].bb ; // RepeatedTiming // First
0.000045
dd == ee1 == ee2
True
$endgroup$
add a comment
|
$begingroup$
n = 4;
m = 3;
aa = Array[a, n, m];
bb = Array[b, n, m];
cc = Array[c, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m];
You can Transpose aa and Dot it with bb cc:
Transpose[aa].(bb cc) == dd
True
Alternatively, you can Transpose aa cc and Dot it with bb:
Transpose[aa cc].bb ==dd
True
Comparison with Table/Sum combination:
SeedRandom[1]
n = 100;
m = 50;
aa = RandomReal[1, n, m];
bb = RandomReal[1, n, m];
cc = RandomReal[1, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m]; //
RepeatedTiming // First
0.417
ee1 = Transpose[aa].( bb cc) ; // RepeatedTiming // First
0.000051
ee2 = Transpose[aa cc].bb ; // RepeatedTiming // First
0.000045
dd == ee1 == ee2
True
$endgroup$
add a comment
|
$begingroup$
n = 4;
m = 3;
aa = Array[a, n, m];
bb = Array[b, n, m];
cc = Array[c, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m];
You can Transpose aa and Dot it with bb cc:
Transpose[aa].(bb cc) == dd
True
Alternatively, you can Transpose aa cc and Dot it with bb:
Transpose[aa cc].bb ==dd
True
Comparison with Table/Sum combination:
SeedRandom[1]
n = 100;
m = 50;
aa = RandomReal[1, n, m];
bb = RandomReal[1, n, m];
cc = RandomReal[1, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m]; //
RepeatedTiming // First
0.417
ee1 = Transpose[aa].( bb cc) ; // RepeatedTiming // First
0.000051
ee2 = Transpose[aa cc].bb ; // RepeatedTiming // First
0.000045
dd == ee1 == ee2
True
$endgroup$
n = 4;
m = 3;
aa = Array[a, n, m];
bb = Array[b, n, m];
cc = Array[c, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m];
You can Transpose aa and Dot it with bb cc:
Transpose[aa].(bb cc) == dd
True
Alternatively, you can Transpose aa cc and Dot it with bb:
Transpose[aa cc].bb ==dd
True
Comparison with Table/Sum combination:
SeedRandom[1]
n = 100;
m = 50;
aa = RandomReal[1, n, m];
bb = RandomReal[1, n, m];
cc = RandomReal[1, n];
dd = Table[Sum[aa[[i, j]] bb[[i, k]] cc[[i]], i, 1, n], j, 1, m, k, 1, m]; //
RepeatedTiming // First
0.417
ee1 = Transpose[aa].( bb cc) ; // RepeatedTiming // First
0.000051
ee2 = Transpose[aa cc].bb ; // RepeatedTiming // First
0.000045
dd == ee1 == ee2
True
edited Jun 16 at 4:00
answered Jun 16 at 3:37
kglrkglr
224k10 gold badges254 silver badges511 bronze badges
224k10 gold badges254 silver badges511 bronze badges
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%2f200432%2fefficient-way-to-sum-over-an-index-repeated-more-than-twice%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