diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-07-02 00:28:55 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-09-12 23:14:10 -0700 |
commit | 0228ebf759bda388ef2712cbca836ea39e13054e (patch) | |
tree | d260b7eb647b1d04da20eb634223c9461e4bd599 | |
parent | 57fe5d04f0e54b5ef92c7bd69b6a31ad7df0bba5 (diff) | |
download | numpy-0228ebf759bda388ef2712cbca836ea39e13054e.tar.gz |
ENH: Add the out parameter to stack too
-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): |