[SciPy-user] confused

Robert Kern robert.kern at gmail.com
Sun Jan 22 13:47:51 CST 2006


balky wrote:

> And one last question if I can - how can I make an array of python 
> classes?

Use object arrays.

In [1]: from numpy import array

In [2]: class A(object):
   ...:     def __init__(self, x):
   ...:         self.x = x
   ...:

In [3]: some_As = array([A(1), A(2), A(3)], object)

In [4]: some_As
Out[4]:
array([<__main__.A object at 0x212af70>, <__main__.A object at 0x212ae30>,
       <__main__.A object at 0x212ac90>], dtype=object)

> How can I tell to scipy that each cell (record) in array should 
> be my own class? Some examples please :)

You can't.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the SciPy-user mailing list