[SciPy-user] How does concatenate work?

dmitrey openopt at ukr.net
Thu Jul 5 03:43:09 EDT 2007


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
>
>
>
>   




More information about the SciPy-User mailing list