[Numpy-discussion] Question regarding concatenate/vstack.

Ralf Gommers ralf.gommers at googlemail.com
Wed Mar 30 12:35:33 EDT 2011


On Wed, Mar 30, 2011 at 1:42 PM, gary ruben <gruben at bigpond.net.au> wrote:
> You're right, they are not equivalent. vstack will happily create an
> array of higher rank than the parts it is stacking, whereas
> concatenate requires the arrays it is working with to already be at
> least 2d, so the equivalent is
> np.concatenate((np.arange(5.)[newaxis],np.arange(5.)[newaxis]), axis=0)
> or
> np.concatenate((np.atleast_2d(np.arange(5.)),np.atleast_2d(np.arange(5.))),
> axis=0)

This is fixed in the docstring now.

Ralf

> On Wed, Mar 30, 2011 at 9:30 PM, andrew nelson <andyfaff at gmail.com> wrote:
>> Dear List,
>> I have a quick question regarding vstack and concatenate.
>> In the docs for vstack it says that:
>>
>> np.concatenate(tup, axis=0)
>>
>> should be equivalent to:
>>
>> np.vstack(tup)
>>
>> However, I tried this out and it doesn't seem to be case, i.e.
>>
>>>>> np.vstack((np.arange(5.), np.arange(5.)))
>> array([[ 0.,  1.,  2.,  3.,  4.],
>>       [ 0.,  1.,  2.,  3.,  4.]])
>>
>>>>> np.concatenate((np.arange(5.),np.arange(5.)), axis=0)
>> array([ 0.,  1.,  2.,  3.,  4.,  0.,  1.,  2.,  3.,  4.])
>>
>> These aren't the same. Maybe I'm missing something?
>>
>> regards,
>> Andrew.
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list