Simple question - Numeric Python

Paul Magwene paul.magwene at yale.edu
Thu Mar 9 12:09:44 EST 2000


Matthew Hirsch wrote:
> 
> Hi All,
> 
> I have a simple question about numeric python.
> 
> If I have the matrix:
> 
> 1 2 3
> 4 5 6
> 7 8 9
> 
> How would you enter this?
> 
> Would it be:
> 1) array(((1,2,3),(4,5,6),(7,8,9)))  or
> 2) array(((1,4,7),(2,5,8),(3,6,9)))
> 
> In other words, are they entered as horizontal or vertical vectors?
> 
> Thanks for your help,
> Matt


When in doubt, try it out! .....


Python 1.5.2 (#2, Dec 22 1999, 19:19:20)  [GCC 2.7.2.3] on freebsd3
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from Numeric import *
>>> a = array(((1,2,3),(4,5,6),(7,8,9)))
>>> a
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])


Of course, if you prefer to enter things by columns you could do:


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


If you're going to be doing anything with Numeric I highly suggest you
download 
and glance through the PDF manual from the Numeric webpage on
sourceforge.


--Paul



More information about the Python-list mailing list