[Numpy-discussion] Bug in dstack?

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Apr 2 19:50:26 EDT 2009


On Thu, Apr 2, 2009 at 6:46 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
> Note:
>
> In [133]: l = [[1,0,0],[1,1,0],[1,1,1]]
>
> In [134]: dstack(l)
> Out[134]:
> array([[[1, 1, 1],
>         [0, 1, 1],
>         [0, 0, 1]]])
>
> In [135]: dstack(l).shape
> Out[135]: (1, 3, 3)
>
>
> Shouldn't the shape be (3,3)? Also, for generalized ufuncs and broadcasting
> I think a function that stacked along the first axis instead of the last
> would be useful. Maybe gstack or astack?
>
> Chuck
>

I think dstack, vstack and hstack work exactly as advertised in the
docs, at least that's how I interpret and use them

Josef

>>> l = [[1,0,0],[1,1,0],[1,1,1]]
>>> np.dstack(l).shape
(1, 3, 3)
>>> np.vstack(l).shape
(3, 3)
>>> np.hstack(l).shape
(9,)
>>> np.vstack(l)
array([[1, 0, 0],
       [1, 1, 0],
       [1, 1, 1]])
>>> np.dstack(l)[:,:,0]
array([[1, 0, 0]])
>>> np.dstack(l)[:,:,1]
array([[1, 1, 0]])
>>> np.dstack(l)[:,:,2]
array([[1, 1, 1]])



More information about the NumPy-Discussion mailing list