Index Error

Dave Angel d at
Wed Nov 21 14:32:26 CET 2012

> <snip>
>> Back to an earlier comment.  I asked if N was ever bigger than x or
>> bigger than y, and you said never.  But your ComputeClasses will have
>> such a case the very first time around, when cx==0, cy==0, and
>> ring_number == 1.
> I doubt this , M confused..

I'll paste an excerpt of the last source I've seen from you:


def GenerateRing(x,y, N): Generates square rings around a point in data
which has 300 columns(x) and 3000 rows(y)
    indices = []
    for i in xrange(-N, N):
        indices.append((x+i, y-N))
        indices.append((x+N, y+i))
        indices.append((x-i, y+N))
        indices.append((x-N, y-i))
    return indices

def ComputeClasses(data):
    radius = .5
    points = []
    for cy in xrange(0, data.height):
        for cx in xrange(0, data.width):

            if data[cy,cx] == (0.0,0.0,0.0):
            else :
                centre = data[cy, cx]

            change = True

            while change:

                for ring_number in xrange(1, 100):
                    change = False
                    new_indices = GenerateRing(cx, cy, ring_number)

When that GenerateRing() is first called, cy will be zero, cx the same,
and ring_number will be 1.

So some of the tuples in the returned list will have negative ints.  You
don't check for that either.

I still think that data.height and data.width aren't the right limits to
be using.



More information about the Python-list mailing list