def distance(c, p):<br>    dist = sqrt(<br>            ((c[0]-p[0])**2) +<br>            ((c[1]-p[1])**2) +<br>            ((c[2]-p[2])**2)<br>            )<br>    return dist         <br><br><br>def GenerateRing(x,y, N): <span style="background-color:rgb(255,242,204)">Generates square rings around a point in data which has 300 columns(x) and 3000 rows(y)</span><br>
    indices = []<br>    for i in xrange(-N, N):<br>        indices.append((x+i, y-N))<br>        indices.append((x+N, y+i))<br>        indices.append((x-i, y+N))<br>        indices.append((x-N, y-i))<br>    return indices<br>
<br><br>def ComputeClasses(data):<br>    radius = .5 <br>    points = []<br>    for cy in xrange(0, data.height):<br>        for cx in xrange(0, data.width): <br>                                        <br>            if data[cy,cx] == (0.0,0.0,0.0):<br>
                continue<br>            else : <br>                centre = data[cy, cx]<br>                points.append(centre)    <br>                <br><br>            change = True  <br><br>            while change: <br>
                <br>                for ring_number in xrange(1, 100): <br>                    change = False<br>                    new_indices = GenerateRing(cx, cy, ring_number) <br>                    print new_indices<br>
                    for idx in new_indices:                                 <span style="background-color:rgb(255,242,204)"> 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</span><br>
                        if idx[0] >= 300 and idx[1] >= 3000:          <span style="background-color:rgb(255,242,204)"> go to next centre and start generating rings from there.. and again if the index is out of range .. this should repeat</span><br>
                            continue<br>                        else :<br>                            point = data[idx[0], idx[1]] <br>                            if point == (0.0, 0.0, 0.0 ):<br>                                print point <br>
                                continue<br>                            else:                <br>                                dist = distance(centre, point)<br>                                print dist <br>                                if  dist < radius :              <span style="background-color:rgb(255,242,204)"> and rings should be added only when this condition is satisfied </span><br>
                                    print point <br>                                    points.append(point)<br>                                    change = True<br>                                    print change<br>                  <br>
                <br>                        break <br>        <span style="background-color:rgb(255,242,204)"><span style></span></span><br>            <br>            print points <br><br><br>ERROR now : <br><br>data loaded<br>
[(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404), (297, 405), (296, 404)] ..<span style="background-color:rgb(255,242,204)">. </span><span style="background-color:rgb(204,0,0)"><span style="background-color:rgb(255,242,204)">I am printing Indices to know what index it dies out..</span><br>
</span><br>Traceback (most recent call last):<br>  File "Z:/modules/Classify.py", line 73, in <module><br>    ComputeClasses(data)<br>  File "Z:/modules/Classify.py", line 49, in ComputeClasses<br>
    point = data[idx[0], idx[1]]<br>error: index is out of range<br><div class="gmail_extra"><br><br><br></div>