Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'error:': 0.05; 'skip:` 10': 0.05; 'completeness': 0.07; 'exit': 0.07; 'indices': 0.07; 'subject:Error': 0.07; 'try:': 0.07; 'exception:': 0.09; 'failure.': 0.09; 'received:155': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'index': 0.13; '0.0,': 0.16; '49,': 0.16; 'dictionary.': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'dist': 0.16; 'from:addr:jpmorgan.com': 0.16; 'idx': 0.16; 'idx,': 0.16; 'indexerror:': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'rings': 0.16; 'securities,': 0.16; 'skip:{ 30': 0.16; 'subject:Index': 0.16; 'there..': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'element': 0.17; 'example.': 0.17; 'skip:\xa0 30': 0.17; 'creates': 0.18; '>>>': 0.18; 'thanks.': 0.21; 'cc:2**0': 0.23; 'elements': 0.23; 'received:169.254': 0.24; 'device': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; 'plain': 0.27; 'possibly': 0.27; 'accuracy': 0.27; 'there.': 0.28; 'actual': 0.28; 'post': 0.28; 'methods.': 0.29; 'no,': 0.29; 'points': 0.29; 'received:169': 0.29; 'error': 0.30; 'point': 0.31; 'file': 0.32; 'structure': 0.32; 'could': 0.32; 'print': 0.32; 'dies': 0.33; 'traceback': 0.33; 'problem': 0.33; 'knowledge': 0.33; 'text': 0.34; 'list': 0.35; 'built-in': 0.35; 'false': 0.35; 'skip:: 10': 0.35; 'so,': 0.35; 'continue': 0.35; 'next': 0.35; 'add': 0.36; 'except': 0.36; 'but': 0.36; 'loaded': 0.36; 'method': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'unable': 0.36; 'two': 0.37; 'item': 0.37; 'skip:3 10': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'takes': 0.39; 'where': 0.40; 'help': 0.40; 'range': 0.60; 'repeat': 0.62; 'different': 0.63; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; '8bit%:100': 0.70; '3000': 0.71; 'lack': 0.71; 'skip:n 40': 0.72; 'square': 0.75; 'sale': 0.76; 'satisfied': 0.83; 'dimensional': 0.84; 'out..': 0.84; 'received:169.254.8': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; '8bit%:67': 0.93 X-DKIM: OpenDKIM Filter v2.1.3 sz2.jpmchase.com qAKKe23P021669 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1353444002; bh=dnhf/DJOhUEjuB9rI/e2FkSx6PtembMZk9McGJAVz8A=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=W4ZrPXe5j+mjm4fPj0KR9O6/om1/Y+UTCj4fOnldEGVPDCZQ9WO8mI0Bh5TSemX47 uVbsGjh+jcgQs+w7T9wDJd3gas6hbAK0u62c9kXaLE0DulFLSh6zJIaFYtveqHtV1f NcDapvy8gVc/WQM5j59noslcsuxofaoxTVLLyFpk= From: "Prasad, Ramit" To: inshu chauhan Subject: RE: Index Error Thread-Topic: Index Error Thread-Index: AQHNxyUdDHiwl6qz1E+cZbUnV/nhOZfzEz1g Date: Tue, 20 Nov 2012 20:39:51 +0000 References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="iso-8859-1" Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353445629 news.xs4all.nl 6925 [2001:888:2000:d::a6]:47507 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33661 Can you please post in plain text and stop top-posting? Thanks=2E =0D=0A=0D= =0Ainshu chauhan wrote:=0D=0A> =0D=0A> def distance(c, p):=0D=0A> =A0=A0=A0= dist =3D sqrt(=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((c[0]-p[0])**2) += =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((c[1]-p[1])**2) +=0D=0A> =A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 ((c[2]-p[2])**2)=0D=0A> =A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 )=0D=0A> =A0=A0=A0 return dist=0D=0A> =0D=0A> =0D=0A> def Gene= rateRing(x,y, N): Generates square rings around a point in data which has 3= 00 columns(x) and 3000=0D=0A> rows(y)=0D=0A> =A0=A0=A0 indices =3D []=0D=0A= > =A0=A0=A0 for i in xrange(-N, N):=0D=0A> =A0=A0=A0=A0=A0=A0=A0 indices=2E= append((x+i, y-N))=0D=0A> =A0=A0=A0=A0=A0=A0=A0 indices=2Eappend((x+N, y+i)= )=0D=0A> =A0=A0=A0=A0=A0=A0=A0 indices=2Eappend((x-i, y+N))=0D=0A> =A0=A0= =A0=A0=A0=A0=A0 indices=2Eappend((x-N, y-i))=0D=0A> =A0=A0=A0 return indice= s=0D=0A=0D=0ANo, this creates a one dimensional list with 2N elements of wh= ere each element is a two item tuple=2E=0D=0A=0D=0A=0D=0A> =0D=0A> =0D=0A> = def ComputeClasses(data):=0D=0A> =A0=A0=A0 radius =3D =2E5=0D=0A> =A0=A0=A0= points =3D []=0D=0A> =A0=A0=A0 for cy in xrange(0, data=2Eheight):=0D=0A> = =A0=A0=A0=A0=A0=A0=A0 for cx in xrange(0, data=2Ewidth):=0D=0A> =0D=0A> =A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if data[cy,cx] =3D=3D (0=2E0,0=2E0,0=2E0):= =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue=0D=0A> =A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else :=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 centre =3D data[cy, cx]=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 points=2Eappend(centre)=0D=0A> =0D=0A> =0D=0A> =A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 change =3D True=0D=0A> =0D=0A> =A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 while change:=0D=0A> =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 for ring_number in xrange(1, 100):=0D=0A> =A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 change =3D False=0D=0A> =A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 new_indices =3D Generat= eRing(cx, cy, ring_number)=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 print new_indices=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 for idx in new_indices:=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= I need help in this part as I am=0D=0A> unable to device a method in which= if the points are out of index,it should stop and=0D=0A> =A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if idx[0] >=3D 300 a= nd idx[1] >=3D 3000:=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 go to next centre and st= art generating=0D=0A> rings from there=2E=2E and again if the index is out = of range =2E=2E this should repeat=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue=0D=0A> =A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else :=0D=0A> = =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 point =3D data[idx[0], idx[1]]=0D=0A=0D=0AYou can use a few differen= t methods=2E This is just one example=2E=0D=0A=0D=0Afor idx, temp_point in = enumerate(new_indices):=0D=0A try:=0D=0A temp_point[0]=0D=0A = temp_point[1]=0D=0A except Exception: #Should be IndexError I think= =2E=0D=0A print 'idx: {0}\ntemp_point:{1}'=2Eformat(idx, temp_point)= =0D=0A # Possibly add a break or exit so you do not have to=0D=0A = # keep going once you hit a failure=2E=0D=0A point =3D data[temp_p= oint[0], temp_point[1]] =0D=0A=0D=0A=0D=0AWhat is `data`? I have not seen a= ny built-in structure that takes=0D=0Aa tuple in this manner=2E=2E=2Eunless= it is a dictionary=2E Or from numpy=2E=0D=0AGiven my lack of knowledge of = what `data`, it could be the=0D=0Aproblem is there=2E That is one reason I = accessed `temp_point[0]` and=0D=0A`temp_point[1]` separately=2E=0D=0A=0D=0A= =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 if point =3D=3D (0=2E0, 0=2E0, 0=2E0 ):=0D=0A> =A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 print point=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue=0D=0A> =A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else:= =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 dist =3D distance(centre, point)=0D=0A> =A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 print dist=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if=A0 dist < radius := =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 and rings should be added only w= hen this=0D=0A> condition is satisfied=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 print point=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 points=2Eappend(poin= t)=0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 change =3D True=0D=0A> =A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 print change=0D=0A> =0D=0A> =0D=0A> =A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 break=0D=0A> =0D=0A>= =0D=0A> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print points=0D=0A> =0D=0A> =0D= =0A> ERROR now :=0D=0A> =0D=0A> data loaded=0D=0A> [(296, 403), (298, 403),= (298, 405), (296, 405), (297, 403), (298, 404), (297, 405), (296, 404)] = =2E=2E=2E I am=0D=0A> printing Indices to know what index it dies out=2E=2E= =0D=0A> =0D=0A> Traceback (most recent call last):=0D=0A> =A0 File "Z:/modu= les/Classify=2Epy", line 73, in =0D=0A> =A0=A0=A0 ComputeClasses(da= ta)=0D=0A> =A0 File "Z:/modules/Classify=2Epy", line 49, in ComputeClasses= =0D=0A> =A0=A0=A0 point =3D data[idx[0], idx[1]]=0D=0A> error: index is out= of range=0D=0A> =0D=0A=0D=0AIs that the actual error? If so, then the prob= lem is not `idx` or =0D=0A`temp_point` but instead `data`=2E If it is not t= he exact error, please =0D=0Acopy and paste the error message *exactly* as = given=2E=0D=0A=0D=0A>>> [1][2]=0D=0AIndexError: list index out of range=0D= =0A>>> (1,2)[3]=0D=0AIndexError: tuple index out of range=0D=0A=0D=0A=0D=0A= ~Ramit=0D=0A=0D=0A=0D=0AThis email is confidential and subject to important= disclaimers and=0D=0Aconditions including on offers for the purchase or sa= le of=0D=0Asecurities, accuracy and completeness of information, viruses,= =0D=0Aconfidentiality, legal privilege, and legal entity disclaimers,=0D=0A= available at http://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E