0

I work on a project that has a lot of hard-to-grasp data shapes.
I'm talking about lists nested as deep as 5 levels. Often I have to reorder the way that data is represented in these lists. For example, I may have to flatten the 4th level and transpose the 3rd with the second, take the mean() of all the values in the 5th level, etc.

My problem : I cannot find an easy way to represent this data in my mind (up to 3D thats ok, but 5...). It is also very hard to comment my code and find new variables names... Here is an example :

for time_position in time_positions:
    # returns values of the form : reaches -> sections -> variables -> values for each variable
    values = self.file.get_section_values(time_position, var_positions)

    # first, we only select the reaches of interest and flatten them at the same level
    # so we have values of the form : all sections -> variables -> values for each l_absc
    all_sections = []
    for reach_position in reaches_positions:
        all_sections += values[reach_position]

    # then, we open each section to get each variable
    agg_sections_vars = []
    for section in all_sections:
        agg_vars = []
        # for each of these variables, we aggregate the values
        for variable in section:
            agg_vars.append(agg_method(variable))
        # and we append them to the section variables list so it is of the form :
        # all sections -> all variables -> aggregated value
        agg_sections_vars.append(agg_vars)
    # now we transpose the agg_sections_vars so that it is of the form :
    # all variables -> all sections -> aggregated values and we concat them i Y
    Y += list(map(list, zip(*agg_sections_vars)))

Do you know a method -- like UML for OOP -- that helps represent nested data so it is easier to grasp and think / talk about ? Or does it comes with experience only ?

Even drawings would help. If you know a way to represent this kind of data with drawings so that it is easyer to understand I'll gladly accept your answer.

Your Answer

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

Browse other questions tagged or ask your own question.