[Numpy-svn] [numpy/numpy] 93d3b8: ENH: add np.stack

GitHub noreply at github.com
Tue May 12 00:43:17 EDT 2015


  Branch: refs/heads/master
  Home:   https://github.com/numpy/numpy
  Commit: 93d3b8dedc5cd602c867a234f07188fe5bd5479b
      https://github.com/numpy/numpy/commit/93d3b8dedc5cd602c867a234f07188fe5bd5479b
  Author: Stephan Hoyer <shoyer at climate.com>
  Date:   2015-05-11 (Mon, 11 May 2015)

  Changed paths:
    M doc/release/1.10.0-notes.rst
    M doc/source/reference/routines.array-manipulation.rst
    M numpy/add_newdocs.py
    M numpy/core/shape_base.py
    M numpy/core/tests/test_shape_base.py
    M numpy/lib/function_base.py
    M numpy/lib/index_tricks.py
    M numpy/lib/shape_base.py

  Log Message:
  -----------
  ENH: add np.stack

The motivation here is to present a uniform and N-dimensional interface for
joining arrays along a new axis, similarly to how `concatenate` provides a
uniform and N-dimensional interface for joining arrays along an existing axis.

Background
~~~~~~~~~~

Currently, users can choose between `hstack`, `vstack`, `column_stack` and
`dstack`, but none of these functions handle N-dimensional input. In my
opinion, it's also difficult to keep track of the differences between these
methods and to predict how they will handle input with different
dimensions.

In the past, my preferred approach has been to either construct the result
array explicitly and use indexing for assignment, to or use `np.array` to
stack along the first dimension and then use `transpose` (or a similar method)
to reorder dimensions if necessary. This is pretty awkward.

I brought this proposal up a few weeks on the numpy-discussion list:
http://mail.scipy.org/pipermail/numpy-discussion/2015-February/072199.html

I also received positive feedback on Twitter:
https://twitter.com/shoyer/status/565937244599377920

Implementation notes
~~~~~~~~~~~~~~~~~~~~

The one line summaries for `concatenate` and `stack` have been (re)written to
mirror each other, and to make clear that the distinction between these functions
is whether they join over an existing or new axis.

In general, I've tweaked the documentation and docstrings with an eye toward
pointing users to `concatenate`/`stack`/`split` as a fundamental set of basic
array manipulation routines, and away from
`array_split`/`{h,v,d}split`/`{h,v,d,column_}stack`

I put this implementation in `numpy.core.shape_base` alongside `hstack`/`vstack`,
but it appears that there is also a `numpy.lib.shape_base` module that contains
another larger set of functions, including `dstack`. I'm not really sure where
this belongs (or if it even matters).

Finally, it might be a good idea to write a masked array version of `stack`.
But I don't use masked arrays, so I'm not well motivated to do that.


  Commit: 18c89dbf87929e68479b2272ad7ab4b321120773
      https://github.com/numpy/numpy/commit/18c89dbf87929e68479b2272ad7ab4b321120773
  Author: Charles Harris <charlesr.harris at gmail.com>
  Date:   2015-05-12 (Tue, 12 May 2015)

  Changed paths:
    M doc/release/1.10.0-notes.rst
    M doc/source/reference/routines.array-manipulation.rst
    M numpy/add_newdocs.py
    M numpy/core/shape_base.py
    M numpy/core/tests/test_shape_base.py
    M numpy/lib/function_base.py
    M numpy/lib/index_tricks.py
    M numpy/lib/shape_base.py

  Log Message:
  -----------
  Merge pull request #5605 from shoyer/stack

ENH: add np.stack


Compare: https://github.com/numpy/numpy/compare/fb6426b3d9b2...18c89dbf8792


More information about the Numpy-svn mailing list