[SciPy-user] How does concatenate work?

iCy-fLaME icy.flame.gm at gmail.com
Thu Jul 5 03:55:30 EDT 2007


Aha.. that works. I see they both have to have the same number of
dimensions for it to work, thanks a lot dmitrey.

On 7/5/07, dmitrey <openopt at ukr.net> wrote:
> try
> b = zeros((1,4))
>
> concatenate((a,b), 0)
> array([[  1.,   2.,   3.,   4.],
>        [  5.,   6.,   7.,   8.],
>        [  9.,  10.,  11.,  12.],
>        [ 13.,  14.,  15.,  16.],
>        [ 17.,  18.,  19.,  20.],
>        [  0.,   0.,   0.,   0.]])
> you may use also
> concatenate((a,b.reshape(1,4)), 0)
> or concatenate((a,b.reshape(1,4)))
> or numpy.hstack((a,b.reshape(1,4)))
> HTH,D
>
> iCy-fLaME wrote:
> > If I have a (m,  n) array, is concatenate is right way to go about
> > making it a (m+1, n) or (m, n+1) array?
> >
> > I tried the following, couldn't figure out how to do it correctly. Any
> > helps are greatly appreciated.
> >
> >
> >>>> from numpy import linspace, zeros
> >>>> from numpy import concatenate
> >>>>
> >>>> a = linspace(1, 20, 20).reshape((5,4))
> >>>> a
> >>>>
> > array([[  1.,   2.,   3.,   4.],
> >        [  5.,   6.,   7.,   8.],
> >        [  9.,  10.,  11.,  12.],
> >        [ 13.,  14.,  15.,  16.],
> >        [ 17.,  18.,  19.,  20.]])
> >
> >>>> b = zeros(4)
> >>>> b
> >>>>
> > array([ 0.,  0.,  0.,  0.])
> >
> >>>> concatenate((a,b), axis=0)
> >>>>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > ValueError: arrays must have same number of dimensions
> >
> >>>> concatenate((a,b), axis=1)
> >>>>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > ValueError: arrays must have same number of dimensions
> >
> >
> >
> >
> >
> > icy
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user at scipy.org
> > http://projects.scipy.org/mailman/listinfo/scipy-user
> >
> >
> >
> >
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>


-- 
iCy-fLaME
------------------------------------------------
The body maybe wounded, but it is the mind that hurts.



More information about the SciPy-User mailing list