2012-05-18 105 views

回答

1

我認爲您正在尋找numpy.dstack()

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. 

希望這有助於。愛Numpy!

+0

另外,你的問題不完全正確。結果數組將有3個維度。每個數組將與這個第三維的其中一個索引相關聯。因此,當你想恢復arrayB時,就像這樣切片:'arrayA_again = multiarray [:,:,0]' – heltonbiker

+0

非常感謝! –

+0

對不起,我在之前的評論中犯了一個錯誤:當你想恢復arrayA(而不是B)時,你可以像這樣切片:'arrayA_again = multiarray [:,:,0]','arrayD_again = multiarray [:,:, 3]'等等。另外,尺寸的數量(numpy的'ndims')應該是三個:高度,寬度和深度,不要與數組的形狀混淆,這可能與您想要的長度相同。如果你有200行和300列的數組,並且你堆棧了20個數組,你會得到一個三維數組,其形狀=(200,300,20)。例如,如果你想要最後一個,你可以切分'multiarray [:,:, - 1]'。 – heltonbiker