creating array of python objects
Jeff Epler
jepler at unpythonic.net
Sun Mar 14 14:37:36 EST 2004
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.
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
More information about the Python-list
mailing list