creating array of python objects
faheem at email.unc.edu
Mon Mar 15 18:21:41 CET 2004
On Sun, 14 Mar 2004 13:37:36 -0600, Jeff Epler <jepler at unpythonic.net> wrote:
> I don't believe that numarray supports arrays of Python objects.
> The list of Numarray types doesn't list them:
> This is the meaning of the "not a numeric type" message.
> Using numpy, you can create an array of PyObjects where each entry is a
> reference to the same cell object:
> >>> class cell:
> ... def setrow(self,row):
> ... self.row = row
> ... def setcol(self,col):
> ... self.col = col
> >>> empcell = cell()
> >>> a = Numeric.reshape([empcell]*4, (2,2))
> >>> a.setrow(10)
> >>> a.row # because they are the same object
Is a[0,0] equivalent to a? It is a slightly more compact representation.
> If you want distinct objects, you'll have to use
> >>> a = Numeric.reshape([cell() for i in range(4)], (2,2))
More information about the Python-list