Index Error

inshu chauhan insideshoes at gmail.com
Wed Nov 21 05:15:56 EST 2012


> >
> > 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
>
> No, this creates a one dimensional list with 2N elements of where each
> element is a two item tuple.
>
> Yes, in programme it returns a list of tuples but pysically it is creating
a ring .

>
>              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]]
>
> You can use a few different methods. This is just one example.
>
> for idx, temp_point in enumerate(new_indices):
>     try:
>         temp_point[0]
>         temp_point[1]
>     except Exception: #Should be IndexError I think.
>         print 'idx: {0}\ntemp_point:{1}'.format(idx, temp_point)
>         # Possibly add a break or exit so you do not have to
>         # keep going once you hit a failure.
>     point = data[temp_point[0], temp_point[1]]
>
>
>
Thank you for the suggestion.


> What is `data`? I have not seen any built-in structure that takes
> a tuple in this manner...unless it is a dictionary. Or from numpy.
> Given my lack of knowledge of what `data`, it could be the
> problem is there. That is one reason I accessed `temp_point[0]` and
> `temp_point[1]` separately.
>

Data is an image.

>
>
> >
> > 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
> >
>
> Is that the actual error? If so, then the problem is not `idx` or
> `temp_point` but instead `data`. If it is not the exact error, please
> copy and paste the error message *exactly* as given.
>


Sorry but this is the actual error .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121121/bb91507b/attachment.html>


More information about the Python-list mailing list