I have several 2-dimentional arrays under a hdf5 file, how can I merge them together into one multi-dimentional array in PyTables?i.e., the file now is array A, arra yB, array C, i want them to be array X with 1st dimension A, 2nd dimension B, 3rd dimension C
Asked
Active
Viewed 181 times
0
-
What do you mean when you say merge? – user545424 May 19 '12 at 00:00
1 Answers
1
I think you are looking for numpy.dstack()
.
From the docs:
Stack arrays in sequence depth wise (along third axis).
Takes a sequence of arrays and stack them along the third axis to make a single array.
All of them must have the same shape along all but the third axis.
Hope this helps. Love Numpy!

heltonbiker
- 26,657
- 28
- 137
- 252
-
Also, your question is not quite correct. The resulting array would have 3 dimensions. Each array would be associated with one of the INDEXES of this third dimension. Thus, when you want to recover arrayB, you slice like this: `arrayA_again = multiarray[:,:,0]` – heltonbiker May 21 '12 at 03:46
-
Sorry, I made a mistake on the previous comment: when you want to recover arrayA (not B), you slice like this: `arrayA_again = multiarray[:,:,0]`, `arrayD_again = multiarray[:,:,3]`, etc. Also, the number of DIMENSIONS (`ndims` for numpy) would be three: height, width and depth, not to be confused with the SHAPE of the array, which might be as long as you want. If you have arrays with 200 rows and 300 colums, and you stack 20 of them, you get a three-dimensional array, with shape = (200, 300, 20). If you want the last one, for example, you can slice `multiarray[:,:,-1]`. – heltonbiker May 21 '12 at 13:06