creating array of python objects
Faheem Mitha
faheem at email.unc.edu
Sun Mar 14 15:06:55 EST 2004
On Sun, 14 Mar 2004, Jeff Epler wrote:
> I don't believe that numarray supports arrays of Python objects.
> The list of Numarray types doesn't list them:
> http://stsdas.stsci.edu/numarray/numarray-0.9.html/node21.html#tab:type-specifiers
>
> This is the meaning of the "not a numeric type" message.
Todd Miller said some stuff had not been documented yet. In any case, this
is from a numarray help page!
> 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[0][0].setrow(10)
> >>> a[1][1].row # because they are the same object
> 10
> If you want distinct objects, you'll have to use
> >>> a = Numeric.reshape([cell() for i in range(4)], (2,2))
>
> Jeff
Thanks for the info. However, I was going by
numarray.objects
FILE
/usr/lib/python2.3/site-packages/numarray/objects.py
DESCRIPTION
objects -- This module defines a class and set of functions for
manipulating arrays of Python objects. It defines functions which
correspond to most of the most of the operators defined in Python's
operator module, and provides names compatible with most of numarray's
universal functions.
...
I thought this meant I *could* create an array of python objects. Am I
misunderstanding something?
Thanks for the help.
Faheem.
More information about the Python-list
mailing list