Suppose I have two very large lists {a1, a2, …} and {b1, b2, …} where all ai and bj are large sparse arrays. For the sake of memory efficiency I store each list as one comprehen
Using your example list
data, I believe that you will find the ability to Append
to a SparseArray
quite helpful.
acc = SparseArray[{}, {1, 2, 2, 2, 2, 2, 2}]
Do[AppendTo[acc, i.j], {i, list}, {j, list}]
Rest[acc]
I need Rest
to drop the first zero-filled tensor in the result. The second argument of the seed SparseArray
must be the dimensions of each of your elements with a prefixed 1
. You may need to explicitly specify a background for the seed SparseArray
to optimize performance.