Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33622 > unrolled thread

Re: Index Error

Started byDave Angel <d@davea.name>
First post2012-11-20 09:46 -0500
Last post2012-11-20 09:46 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Index Error Dave Angel <d@davea.name> - 2012-11-20 09:46 -0500

#33622 — Re: Index Error

FromDave Angel <d@davea.name>
Date2012-11-20 09:46 -0500
SubjectRe: Index Error
Message-ID<mailman.59.1353422809.29569.python-list@python.org>
On 11/20/2012 09:26 AM, inshu chauhan wrote:
>> 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
>>>
>> Is it possible that N is greater than either x or y ?  Are negative
>> subscripts permissible?
>>
>> You should consider doing the clipping logic in this function, perhaps
>> by passing xlimit and ylimit in as arguments.>
>>
> 
> 
> Yes N cannot be greater than x and y and it cant be negative too...
> 
>>      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
> 
> This is where you're trying to clip the values that may be outside of
>> the total matrix.
>>
> 
> Yes I am trying to clip the values here but its not working actually , I
> mean not at all working
> 

So did you read the following paragraphs?  You should not be using "and"
in that expression.

>>
>> You do not want "and" in that expression.  The way you've coded it,
>> it'll only skip items in which both indices are out of range.  Change it to
>>                   if idx[0] >= data.width or idx[1] >= data.height:
>>
>> and depending on your answer to my earlier query, you may want to also
>> check if either subscript is negative.
>>
>>>                             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
>>
>> Why do you want to terminate the loop after only iteration?
>>
> 
> I dint get your question ??
> 

You have a break there.  What's it for?  It'll make sure you only
process one of the idx values from new_indices.  i doubt that's what you
intended.


-- 

DaveA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web