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


Groups > comp.lang.python > #33616

Re: Index Error

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'error:': 0.05; 'function,': 0.07; 'indices': 0.07; 'subject:Error': 0.07; 'logic': 0.09; 'negative.': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'index': 0.13; 'passing': 0.15; '"and"': 0.16; '0.0,': 0.16; '49,': 0.16; 'dist': 0.16; 'expression.': 0.16; 'idx': 0.16; 'query,': 0.16; 'range.': 0.16; 'rings': 0.16; 'subject:Index': 0.16; 'there..': 0.16; 'wrote:': 0.17; 'skip': 0.17; 'trying': 0.21; 'earlier': 0.21; 'terminate': 0.22; 'device': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'values': 0.26; '(most': 0.27; 'am,': 0.27; 'cc:addr:gmail.com': 0.27; 'arguments.': 0.29; 'coded': 0.29; 'points': 0.29; 'error': 0.30; 'point': 0.31; 'file': 0.32; 'print': 0.32; 'dies': 0.33; 'traceback': 0.33; 'false': 0.35; 'doing': 0.35; 'continue': 0.35; 'next': 0.35; 'loaded': 0.36; 'method': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'unable': 0.36; 'possible': 0.37; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'your': 0.60; 'range': 0.60; "you've": 0.61; 'repeat': 0.62; 'total': 0.65; 'header:Reply-To:1': 0.68; '3000': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'square': 0.75; 'satisfied': 0.83; 'matrix.': 0.84; 'out..': 0.84; 'received:74.208.4.194': 0.84; 'subscripts': 0.84; 'clip': 0.93
Date Tue, 20 Nov 2012 09:12:01 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To inshu chauhan <insideshoes@gmail.com>
Subject Re: Index Error
References <CAFqGZRHSZ2QTqw=_iZWCWVJXVoxEZvHkTEmb-QeohRer2hjj7w@mail.gmail.com>
In-Reply-To <CAFqGZRHSZ2QTqw=_iZWCWVJXVoxEZvHkTEmb-QeohRer2hjj7w@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:zXgcPFrrEok+LexgsUkqkTNREnZoli+sKZNUb+/+it8 ayA3p+DFouoDKjD5WPbMvH0tNEL+Wu6YMr8mWfMyDa0LKEwU/w NbNVG8RB6SEXcjXTQmCg7/blvgeaKy4hZbNRT27MPCvWqIDo/K Sjx8pIjJ/KqpkYouwlFTavkALaYGrO6fwy8y7BvVAlTEcC+DGk wOByM6QsCupw74A2ThKpfs+h/UJGo31vlRdk2p4UFDpnLS/ZAm k27xJjZYRv7hsx5FZkJJRWjNdRoZALG0LgYrKt1o/UPMYQsdtq IXB+XVc1JkCo/ok37KHCoIurkSTNn0Ofj/Ornjyv+Zk+l3Kjw= =
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.54.1353420744.29569.python-list@python.org> (permalink)
Lines 113
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353420744 news.xs4all.nl 6942 [2001:888:2000:d::a6]:43517
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33616

Show key headers only | View raw


On 11/20/2012 08:43 AM, inshu chauhan wrote:
> 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
> 
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.



> 
> 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

This is where you're trying to clip the values that may be outside of
the total matrix.

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?

> 
> 
>             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
> 


-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web