Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33611
| Date | 2012-11-20 14:43 +0100 |
|---|---|
| Subject | Index Error |
| From | inshu chauhan <insideshoes@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.49.1353419032.29569.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
def distance(c, p):
dist = sqrt(
((c[0]-p[0])**2) +
((c[1]-p[1])**2) +
((c[2]-p[2])**2)
)
return dist
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)
print new_indices
for idx in new_indices:
I need help in this part as I am unable to device a method in
which if the
points are out of index,it should stop and
if idx[0] >= 300 and idx[1] >= 3000: go
to next centre and start generating rings from there.. and again if the
index is out of range .. this should repeat
continue
else :
point = data[idx[0], idx[1]]
if point == (0.0, 0.0, 0.0 ):
print point
continue
else:
dist = distance(centre, point)
print dist
if dist < radius : and rings
should be added only when this condition is satisfied
print point
points.append(point)
change = True
print change
break
print points
ERROR now :
data loaded
[(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404),
(297, 405), (296, 404)] ... I am printing Indices to know what index it
dies out..
Traceback (most recent call last):
File "Z:/modules/Classify.py", line 73, in <module>
ComputeClasses(data)
File "Z:/modules/Classify.py", line 49, in ComputeClasses
point = data[idx[0], idx[1]]
error: index is out of range
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Index Error inshu chauhan <insideshoes@gmail.com> - 2012-11-20 14:43 +0100
csiph-web