Numeric array of objects

Josiah Carlson jcarlson at nospam.uci.edu
Wed Mar 3 21:43:50 EST 2004


> You create a 1-D Numeric array of n floats with
> 
> x = zeros(n,Float)
> 
> How do you create a Numeric array of n instances of class 'xy', where
> for example xy is defined as follows:
> 
> class xy:
>     def __init__(self,x=0.0,y=0.0):
>         self.x = x
>         self.y = y
> 
> I want the elements of the array to be initialized to the default
> value of xy, (0.0,0.0). I have read the Martelli's explanation on p309
> of the book "Python in a Nutshell", but I still don't get it.


Numeric.array([xy() for i in xrange(n)], Numeric.PyObject)


  - Josiah



More information about the Python-list mailing list