[Numpy-discussion] object dtype questions

Mark Wendell mark.wendell@gmail....
Sat Sep 5 12:22:39 CDT 2009


When I create an array with a dtype=object, and instance a custom
python class to each array member, have I foregone any opportunity to
call methods or get/set attributes on those instances with any of
numpy's 'group' operations? In other words, it seems like once I've
got a custom object as an array member, the only way to get at it is
by accessing it individually, by looping through each member of the
array one at a time.

For example:

Say that C is a simple python class with a couple attributes and methods.

a = np.empty( (5,5), dtype=object)
for i in range(5):
     for j in range(5):
          a[i,j] = C(var1,var2)

First question: is there a quicker way than above to create unique
instances of C for each element of a?

for i in range(5):
     for j in range(5):
          a[i,j].myMethod(var3,var4)
          print a[i,j].attribute1

Again, is there a quicker way than above to call myMethod or access attribute1?


Thanks in advance. I've been searching through the docs for examples
of the use of custom python objects, but haven't found much.
Mark



-- 
--
Mark Wendell


More information about the NumPy-Discussion mailing list