Timeline for Performing sparse sum on Mathematica
Current License: CC BY-SA 4.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 5, 2022 at 0:31 | vote | accept | pseudo spin | ||
Mar 5, 2022 at 0:30 | answer | added | kglr | timeline score: 4 | |
Mar 5, 2022 at 0:29 | comment | added | pseudo spin | @kglr Using this on a test case, I think this works fine! Do you want to post this as an answer so I can accept it? | |
Mar 5, 2022 at 0:08 | comment | added | kglr | please note that mathematica indices start at 1 (not at 0). | |
Mar 5, 2022 at 0:06 | comment | added | kglr |
Total[s[[## & @@ #]] s[[## & @@ #2]] FOO[##] & @@@ Tuples[nzp, 2]] should give the same result.
|
|
Mar 4, 2022 at 23:59 | comment | added | pseudo spin | @kcr Not as far as I can tell -- there possibly is but it would be hard to figure it out | |
Mar 4, 2022 at 23:57 | comment | added | kglr |
one possible way: check if this gives what you need: g = SparseArray[g]; nzp = s["NonzeroPositions"]; Sum[s[[## & @@ i]] s[[## & @@ j]] FOO[i, j], {i, nzp}, {j, nzp}]
|
|
Mar 4, 2022 at 23:55 | comment | added | user49048 | @pseudospin is there a condition that determines which elements are zero based on the symmetries of the indices? it was not clear to me from the OP that's why I am asking | |
Mar 4, 2022 at 23:47 | comment | added | pseudo spin | @kglr No, terribly sorry -- I meant that I have a product of three quantities, which are functions of 12 indices, and I want to sum over those indices. I have edited my question to make this clearer!! | |
Mar 4, 2022 at 23:46 | history | edited | pseudo spin | CC BY-SA 4.0 |
added 28 characters in body
|
Mar 4, 2022 at 23:45 | comment | added | kglr |
pseudo spin, by g[[i,j,k,l,m,n]] x g[[o,p,q,r,s,t]] x ... did you mean g[[i,j,k,l,m,n]] + g[[o,p,q,r,s,t]] + ... ?
|
|
Mar 4, 2022 at 23:43 | comment | added | pseudo spin | @kglr How does that help me evaluate this sum? I understand that I can use NonzeroPositions to determine which elements of my array g are nonzero, but how do I then restrict the sum to only these values of the indices? | |
Mar 4, 2022 at 23:42 | comment | added | kglr | Thank you very much @GregHurst (didn't know about the v13.0 update). | |
Mar 4, 2022 at 23:37 | comment | added | Greg Hurst |
@kglr those properties are now documented and this one is referred to as "ExplicitPositions" . reference.wolfram.com/language/ref/SparseArray.html#1948657
|
|
Mar 4, 2022 at 23:04 | comment | added | kglr |
tried SparseArray and the property "NonzeroPositions" ? See also: What are SparseArray Properties? How and when should they be used?
|
|
S Mar 4, 2022 at 22:30 | review | First questions | |||
Mar 4, 2022 at 23:22 | |||||
S Mar 4, 2022 at 22:30 | history | asked | pseudo spin | CC BY-SA 4.0 |