[Numpy-discussion] array manipulation

Warren Weckesser warren.weckesser at enthought.com
Tue Aug 17 11:08:49 EDT 2010


Alex Ter-Sarkissov wrote:
> hi, this is probably a very silly question, but I can't get my hear 
> around it unfortunately( 
>
> I have an array (say, mat=rand(3,5)) from which I 'pull out' a row 
> (say, s1=mat[1,]). The problem is, the shape of this row s1 is not 
> [1,5], as I would expect, but rather [5,], which means that I can't, 
> for example, concateante mat and s1 rowwise.
>

You can use a trivial slice:

In [9]: a
Out[9]:
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])

In [10]: a[1]      # This is a 1D array.
Out[10]: array([5, 6, 7, 8, 9])

In [11]: a[1:2]    # This is a 2D array.
Out[11]: array([[5, 6, 7, 8, 9]])


Warren


>  
>
> thanks for the help 
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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