[Numpy-discussion] Stacking arrays along new dimension in front

Skipper Seabold jsseabold@gmail....
Tue Jul 20 09:49:57 CDT 2010


On Tue, Jul 20, 2010 at 10:35 AM, Gael Varoquaux
<gael.varoquaux@normalesup.org> wrote:
> On Tue, Jul 20, 2010 at 10:24:56AM -0400, Skipper Seabold wrote:
>> Will one of the stack functions do?  I take it your a looks something like
>
>> a = [np.arange(1000), np.arange(1000), np.arange(1000)]
>
>> np.all(np.vstack(a) == np.concatenate([a_[None] for a_ in a]))
>> # True
>
> Works only for 1D arrays:
>
> In [3]: b = np.arange(100).reshape((10, 10))
>
> In [4]: a = [b, b, b]
>
> In [5]: np.all(np.vstack(a) == np.concatenate([a_[None] for a_ in a]))
> Out[5]: False
>

Hmm, yeah, wouldn't work without reshaping.

np.r_[a]

works, but isn't going to win you any speed contests.

Skipper


More information about the NumPy-Discussion mailing list