# Calculating Averages in Data Trees Without Using Explode Component

Hello everyone,

I am trying to perform calculations within a data tree without using the explode component, as I want it to be flexible depending on the lengths of each branch in the tree.
Specifically, I want to calculate the average of each row while keeping the main trees separate from each other. I am finding it difficult to perform even simpler operations, such as additions, due to the structure of these trees.

Any advice would be greatly appreciated.

Thank you,
Matteo

Which âexplodeâ component were you using?

Did you use the âaverageâ component?

LoL - sorry, silly questions - how about you post a file for someone to help?

1 Like

I havenât used the âExplode Treeâ because I wanted it to be flexible.

The âAverageâ component doesnât work because it averages the n values inside each list, not the rows of each tree. If it were a simple data structure (e.g., {0;0}, {0;1}, {0;2}, {0;3},âŠ) I could have used âFlip Matrixâ > âAverageâ > âFlip Matrixâ again, but I have complex data structure (e.g., {0;0}, {0;1}, {1;0}, {1;1},âŠ) and âFlip Matrixâ doesnât work.

However, hereâs the solution I found: using the âPath Mapperâ component ({A;B} to {A}) and a python script to compute the average, that works with lists whose length is a multiple of the specified interval (8760 in my case).

Hereâs the script if anyone needs it in the future:

``````interval = 8760
result = [0] * interval
for i in range(len(data)):
result[i % interval] += data[i]
divisor = len(data) // interval
result = [x / divisor for x in result]
``````

1 Like

A colleague of mine has found a more effective and clean way to solve the problem. Here it is:

I think it is nice that you found a solution, but I would raise more attention on how to get help here. If you provide an example, so that people do not need to recreate the same problem first, then this makes it easier for anyone to help. Other than that, I found it difficult to follow your explanation. It really helps to pay more attention to explain the problem as easy as possible and to give a simple example everyone can follow. You could have shared an example with the explode component for instance.