[SciPy-user] How does concatenate work?

dmitrey openopt@ukr....
Thu Jul 5 02:43:09 CDT 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@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
>
>   



More information about the SciPy-user mailing list