Numpy Anamoly

Pete Shinners pshinners at mediaone.net
Tue Aug 22 02:03:55 EDT 2000


I have a strange situation with numpy. I'm using a simple 2D array
to store class instances. The problem is, on my Win98 machine (with
all the latest versions py1.5.2, numpy15.3) when in index into the
array i am getting a 1-element-array (scalar?). On every other
platform, indexing the array returns me the class instance in
the array.

I know there's arguments for this working either way, but what
i really care about is that it work the same on all platforms.
here is the sample code...


#############################################
#test array lookup

from Numeric import *

class Tester:
    def DoIt(self):
        return 'DoIt'

a = array(((Tester(),)*3,)*3)
print a[1,1].DoIt()    #here is the bad?? call
##############################################


(sorry if this is an ugly way to create a 2d array
of class instances. i couldn't find a prettier method)

now running this on Win98 gives me an exception...
    print a[1,1].DoIt()
AttributeError: DoIt

an easy fix, but what's strange is on WinNT, IRIX, and LINUX
(also with latest versions (i've quadruple-checked) this code
works as i expect.

so how should i write this code so it works correctly for
everyone's machines??







More information about the Python-list mailing list