diff options
-rw-r--r-- | doc/release/1.14.0-notes.rst | 8 | ||||
-rw-r--r-- | numpy/core/shape_base.py | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/doc/release/1.14.0-notes.rst b/doc/release/1.14.0-notes.rst index 94626ed78..11ee9c008 100644 --- a/doc/release/1.14.0-notes.rst +++ b/doc/release/1.14.0-notes.rst @@ -211,10 +211,10 @@ selected via the ``--fcompiler`` and ``--compiler`` options to supported; by default a gfortran-compatible static archive ``openblas.a`` is looked for. -``concatenate`` gained an ``out`` argument ------------------------------------------- -A preallocated buffer of the desired dtype can now be used with ``concatenate``. - +``concatenate`` and ``stack`` gained an ``out`` argument +-------------------------------------------------------- +A preallocated buffer of the desired dtype can now be used for the output of +these functions. Changes ======= diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index f1847d7e3..026ad603a 100644 --- a/numpy/core/shape_base.py +++ b/numpy/core/shape_base.py @@ -293,7 +293,7 @@ def hstack(tup): return _nx.concatenate(arrs, 1) -def stack(arrays, axis=0): +def stack(arrays, axis=0, out=None): """ Join a sequence of arrays along a new axis. @@ -309,6 +309,10 @@ def stack(arrays, axis=0): Each array must have the same shape. axis : int, optional The axis in the result array along which the input arrays are stacked. + out : ndarray, optional + If provided, the destination to place the result. The shape must be + correct, matching that of what stack would have returned if no + out argument were specified. Returns ------- @@ -358,7 +362,7 @@ def stack(arrays, axis=0): sl = (slice(None),) * axis + (_nx.newaxis,) expanded_arrays = [arr[sl] for arr in arrays] - return _nx.concatenate(expanded_arrays, axis=axis) + return _nx.concatenate(expanded_arrays, axis=axis, out=out) class _Recurser(object): |