[Numpy-discussion] numpy.stack -- which function, if any, deserves the name?

Stefan Otte stefan.otte at gmail.com
Mon Mar 16 04:50:34 EDT 2015


> 1. np.stack for stacking like np.asarray(np.bmat(...))
> http://thread.gmane.org/gmane.comp.python.numeric.general/58748/
> https://github.com/numpy/numpy/pull/5057

I'm the author of this proposal. I'll just give some context real quickly.

"My stack" started really simple, basically allowing a Matlab-like
notation for stacking:

matlab: [ a b; c d ]
numpy: stack([[a, b], [c, d]]) or even stack([a, b], [c, d])

where a, b, c, and d a arrays.

During the discussion people asked for fancier stacking and auto
filling of non explicitly set blocks (think of an "eye" matrix where
only certain blocks are set).

Alternatively, we thought of refactoring the core of bmat [2] so that
it can be used with arrays and matrices. This would allow stack("a b;
c d") where a, b, c, and d are the names of arrays/matrices. (Also
bmat would get better documentation during the refactoring :)).

Summarizing, my proposal is mostly concerned how to create block
arrays from given arrays. I don't care about the name "stack". I just
used "stack" because it replaced hstack/vstack for me. Maybe "bstack"
for block stack, or "barray" for block array?

I have the feeling [1] that my use case is more common, but I like the
second proposal.


[1] Everybody generalizes from oneself. At least I do.
[2] http://docs.scipy.org/doc/numpy/reference/generated/numpy.bmat.html

More information about the NumPy-Discussion mailing list