1

I have several N-dimensional arrays of different shapes and want to combine them into a new (N+1)-dimensional array, where the new axis has a length corresponding to the number of initial N-d arrays.

This answer is sufficient if the original arrays are all the same shape; however, it does not work if they have different shapes.

I don't really want to reshape the arrays to a congruent size and fill with empty elements due to the subsequent analysis I need to perform on the final array.

Specifically, I have four 4D arrays. One of the things I want to do with the resulting 5D array is plot parts of the four arrays on the same matplotlib figure. Obviously I could plot each one separately, however soon I will have more than four 4D arrays and am looking for a dynamic solution.

Community
  • 1
  • 1
airdas
  • 872
  • 2
  • 11
  • 19

1 Answers1

3

While I was writing this, Sven gave the same answer in the comments...

Put the arrays in a python list in the following manner:

5d_list = []
5d_list.append(4D_array_1)
5d_list.append(4D_array_2)
...

Then you can unpack them:

for 4d_array in 5d_list:
    #plot 4d array on figure
Billyziege
  • 56
  • 6