[Numpy-discussion] Reshaping along an axis

Tim Hochberg tim.hochberg at cox.net
Fri Sep 3 06:53:04 EDT 2004


Karthikesh Raju wrote:

>Hi all,
>
>Suppose i have a tuple or a 1D array as
>
>a = (1,2,3,4,5,6,7,8,9)
>
>presently reshape(a,(3,3)) gives me
>
>1 2 3
>4 5 6
>7 8 9
>
>i.e reshaping is done column wise. How do one specifiy reshape to work row
>wise as: reshape(a,(3,3)) =
>1 4 7
>2 5 8
>3 6 9
>  
>

Use transpose pluse reshape:

 >>> a = (1,2,3,4,5,6,7,8,9)
 >>> print transpose(reshape(a, (3,3)))
[[1 4 7]
 [2 5 8]
 [3 6 9]]

-tim


>With warm regards
>
>karthik
>
>
>-----------------------------------------------------------------------
>Karthikesh Raju,		    email: karthik at james.hut.fi
>                                           karthikesh.raju at gmail.com
>Researcher,			    http://www.cis.hut.fi/karthik
>Helsinki University of Technology,  Tel: +358-9-451 5389
>Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
>Department of Computer Sc.,
>P.O Box 5400, FIN 02015 HUT,
>Espoo, FINLAND
>-----------------------------------------------------------------------
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by BEA Weblogic Workshop
>FREE Java Enterprise J2EE developer tools!
>Get your free copy of BEA WebLogic Workshop 8.1 today.
>http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
>_______________________________________________
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>  
>






More information about the NumPy-Discussion mailing list