[Numpy-discussion] array manipulation

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Aug 17 00:25:00 EDT 2010


On Tue, Aug 17, 2010 at 12:13 AM, Alex Ter-Sarkissov <ater1980 at gmail.com> 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.

try
np.vstack((mat[0], mat))

np.arrays are not matrices,
a slice with a single number reduces dimenson,  mat[0] which is
identical to mat[0,:] for 2d array
mat[0][np.newaxis,:] adds a new (row) dimension

>>> mat[0][np.newaxis,:].shape
(1, 5)

it is described somewhere in the help on slicing and indexing

Josef

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