2
$\begingroup$

I am doing a computation, it gives a nested list with a bunch of dimensions:

list={{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1., 1, 1}}, {{0, 0, 0, 0}, {0, 0, 
0, 0}, {0, 0., 0, 0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0., 0, 
0}}}, {{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0., 0, 0}}, {{0, 0, 0, 
0}, {0, 0, 0, 0}, {0, 0., 0, 0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0,
 0., 0, 0}}}, {{{1, 7, 17, 31}, {7, 7, 17, 31}, {17, -0.92, 1, 
31}}, {{1, 4, 9, 16}, {4, 4, 9, 16}, {9, 0.04, 1, 16}}, {{0, 0, 0,
 0}, {0, 0, 0, 0}, {0, 0., 0, 0}}}, {{{0, 0, 0, 0}, {0, 0, 0, 
0}, {0, 0., 0, 0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0., 0, 
0}}, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0., 0, 0}}}, {{{1, 73, 433, 
1441}, {73, 73, 433, 1441}, {433, 0.7696, 1, 1441}}, {{1, 52, 297,
 976}, {52, 52, 297, 976}, {297, -0.1136, 1, 976}}, {{1, 16, 81, 
256}, {16, 16, 81, 256}, {81, 0.0016, 1, 256}}}}

The list dimension is {5,3,3,4} in this example, but it can be other dimensions depending on computation.

But for this example, if I want to calculate the addition of each element that resides in the deepest level of the list in a "parallel" way.(The "parallel" is the only word I can think of to describe what will happen in terms of addition in my case.)

From my observations, I can treat my list as a multi-dimensioned array with 15 blocks, and each block has 3 X 4 elements, I am not sure if thinking in this way would be the best, but this is easy to understand:

enter image description here

So I want to add each of them all together to get a new list that its dimension should be 3 X 4 finally.

May I ask is there an good way to implement this?

Sorry for the irregular diagram , hope I describe my question well.

$\endgroup$
5
$\begingroup$
Total[data,2]

.................

$\endgroup$
  • $\begingroup$ oh, right. okay... thanks very much! $\endgroup$ – cj9435042 Jan 14 '18 at 22:23
  • $\begingroup$ You're welcome! $\endgroup$ – Henrik Schumacher Jan 15 '18 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.