Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33734
| Date | 2012-11-21 08:32 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Index Error |
| References | <CAFqGZRGWginSj-OAA3z7afXzBHuyH6n0By_8hU0J_8i7r1O9_w@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.152.1353504762.29569.python-list@python.org> (permalink) |
>
> <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):
continue
else :
centre = data[cy, cx]
points.append(centre)
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.
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Index Error Dave Angel <d@davea.name> - 2012-11-21 08:32 -0500
csiph-web