wabash
wabash

Reputation: 839

2d array function months

I have monthly data of 25 total years. I split the monthly data in Januarys, Februarys, etc. to have 25 points each (so each month for the 25 years). Then in order to rebuild the original data array, a function was made:

def merge_months(split_data):
    merged_months = []
    for value in range(split_data.shape[1]):
        for month in range(split_data.shape[0]):
            merged_months.append(split_data[month][value])
    return merged_months

Upvotes: 0

Views: 51

Answers (1)

Stefan
Stefan

Reputation: 957

You can simply implement the function in a loop so the function is applied 6 times to reshuffle the (12,25) data:

merged_3d = []
for i in range(len(multi_dim_array)): #multi_dim_array being your (6,12,25) data
    merged_3d.append(merge_months(multi_dim_array[i]))

This returns (6,300) shaped data.

Upvotes: 1

Related Questions