creating array of python objects

Jeff Epler jepler at
Sun Mar 14 20:37:36 CET 2004

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[0][0].setrow(10)
    >>> a[1][1].row         # because they are the same object
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 mailing list