<div dir="ltr">There are two usual ways to combine a sequence of arrays into a new array:<div>1. concatenated along an existing axis</div><div>2. stacked along a new axis</div><div><br></div><div>For 1, we have np.concatenate. For 2, we have np.vstack, np.hstack, np.dstack and np.column_stack. For arrays with arbitrary dimensions, there is the np.array constructor, possibly with transpose to get the result in the correct order. (I've used this last option in the past but haven't been especially happy with it -- it takes some trial and error to get the axis swapping or transpose right for higher dimensional input.)</div><div><br></div><div>This methods are similar but subtly distinct, and none of them generalize well to n-dimensional input. It seems like the function we are missing is the plain np.stack, which takes the axis to stack along as a keyword argument. The exact desired functionality is clearest to understand by example: </div><div><br></div><div><div>>>> X = [np.random.randn(100, 200) for i in range(10)]<br></div><div><div>>>> stack(X, axis=0).shape</div><div>(10, 100, 200)</div><div>>>> stack(X, axis=1).shape</div><div>(100, 10, 200)<br></div><div>>>> stack(X, axis=2).shape</div></div></div><div><div>(100, 200, 10)</div></div><div><br></div><div>So I'd like to propose this new function for numpy. The desired signature would be simply np.stack(arrays, axis=0). Ideally, the confusing mess of other stacking functions could then be deprecated, though we could probably never remove them.</div><div><br></div><div>Matthew Rocklin recent wrote an out of core version this for his dask project (part of Blaze), which is what got me thinking about the need for this functionality:</div><div><div><a href="https://github.com/ContinuumIO/dask/pull/30">https://github.com/ContinuumIO/dask/pull/30</a><br></div></div><div><br></div><div>Cheers,</div><div>Stephan</div></div>