Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:not': 0.03; 'else:': 0.03; 'modifying': 0.07; 'blue': 0.09; 'pixel': 0.09; 'cc:addr:python-list': 0.11; '65536': 0.16; '??\xa0': 0.16; 'co- ordinate': 0.16; 'coordinates': 0.16; 'csv': 0.16; 'loops': 0.16; 'once.': 0.16; 'traverse': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'file,': 0.19; 'cc:addr:python.org': 0.22; 'print': 0.22; 'replace': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'read,': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'ball': 0.31; 'file': 0.32; 'run': 0.32; 'text': 0.33; 'says': 0.33; 'url:python': 0.33; 'running': 0.33; '(e.g.': 0.33; 'checking': 0.33; 'fri,': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'pm,': 0.38; 'url:mail': 0.40; 'full': 0.61; 'new': 0.61; 'course': 0.61; 'first': 0.61; 'information': 0.63; 'taking': 0.65; '26,': 0.68; 'subject:For': 0.78; '14:': 0.84; 'otten': 0.84; 'to:none': 0.92; 'dirty': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:cc:content-type; bh=/sh8d0gImpoxibwBDIlts/ppVf0Nuof+IgAjVpJWfE0=; b=wPE4dhtuv6s9vMVAwyfomWC67Drhox/5kAKTZKLJ42WSMjp+RwfI4k0s2P1RfsboFu hfzLI5GWkD+PdDPSutGlLivHJv7nSg9WEYqZUgXBjxmzvmax6KnxpnMlMeSa1cgAhQDF bMGv9w9EiPZLU9huIUHsD5eAkod0jLDCSDXLu5RExBcXJa5COPqiD1h4GPM0TzWWJDfm YSM4qc3qNNEzYzDJLf6mIWEoUXMZeAL3JwbTx5PVv/feWxZgUqKdlTLtoPGsGr4ly0G8 dip1CvAfWEclb/nBnWwot8v/1C11Jg+XJG599Ifny/I1fk37v7Goz+RDVFEzHB5asz8r uygQ== MIME-Version: 1.0 X-Received: by 10.50.129.99 with SMTP id nv3mr1299929igb.97.1366968994907; Fri, 26 Apr 2013 02:36:34 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Apr 2013 15:06:34 +0530 Subject: Re: Nested For loop not running full From: inshu chauhan Cc: "python-list@python.org" Content-Type: multipart/alternative; boundary=047d7b3a91e65c4ae104db4045e7 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: 175 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366968997 news.xs4all.nl 15876 [2001:888:2000:d::a6]:43921 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44401 --047d7b3a91e65c4ae104db4045e7 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__@web.de> wrote: > inshu chauhan wrote: > > > I have this part of my code where I am trying to traverse over an image > by > > running a for loop for both x and y co-ordinate axis. But the loop is > > terminating by just reading first pixel. Can think of a reason why this > is > > happening ? > > > > The code is: > > for sy in xrange(0, segimage.height): > > for sx in xrange(0, segimage.width): > > if segimage[sy,sx] == (0.0, 0.0, 0.0): > > continue > > else: > > seg_color = segimage[sy,sx] > > blue = int(seg_color[0]) > > green = int(seg_color[1]) > > red = int(seg_color[2]) > > reg_num = blue + 256 * green + 65536 * red > > for l in f: > > sp = l.split(",") > > if len(sp) == 14: > > print sy, sx # for checking which pixel its > > reading currently > > print reg_num, sp[0] # for checking whats > > happening > > if reg_num == int(sp[0].strip()): > > print reg_num, sp[0].strip() # for checking > > whats happening > > classification = int(sp[13].strip()) > > > > > > The inside "for loop" is for reading a csv format file from which I am > > extracting some information. > > My crystal ball says that the 'for sy...' and 'for sx...' loops are running > to completion, but you don't get the coordinates printed because you put > them into the 'for l in f' loop which will only run once. > Is there any means by which I can run this 'For l in f' loop again and again ? > > The quick and dirty fix is to replace > > f = open(...) > > in the code you are not showing with > > f == list(open(...)) > f is just a text file(csv format).. so why list ?? > The reasonable thing to do is of course to move the preprocessing (e.g. > csv- > parsing) out of the sy and sx loops. > I did this but again then what I intend to do is not really happening, For every pixel I read, I want to traverse the full file, so that the information I am taking from pixel have to match in one of the line in the file. Can this be done by modifying my code ? or something new has to be devised ? > -- > http://mail.python.org/mailman/listinfo/python-list > --047d7b3a91e65c4ae104db4045e7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <= __peter__@web.de&= gt; wrote:
insh= u chauhan wrote:

> I have this part of my code where I am trying to traverse over an imag= e by
> running a for loop for both x and y co-ordinate axis. But the loop is<= br> > terminating by just reading first pixel. Can think of a reason why thi= s is
> happening ?
>
> The code is:
> for sy in xrange(0, segimage.height):
> =A0 =A0 for sx in xrange(0, segimage.width):
> =A0 =A0 =A0 =A0 =A0 =A0 if segimage[sy,sx] =3D=3D (0.0, 0.0, 0.0):
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue
> =A0 =A0 =A0 =A0 =A0 =A0 else:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 seg_color =3D segimage[sy,sx]
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 blue =3D int(seg_color[0])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 green =3D int(seg_color[1])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 red =3D int(seg_color[2])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg_num =3D blue + 256 * green + 65536= * red
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for l in f:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sp =3D l.split(",")<= br> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if len(sp) =3D=3D 14:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print sy, sx =A0# for = checking which pixel its
> reading currently
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print reg_num, sp[0] = =A0# for checking whats
> happening
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if reg_num =3D=3D int(= sp[0].strip()):
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print reg_num,= sp[0].strip() # for checking
> whats happening
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 classification= =3D int(sp[13].strip())
>
>
> The inside "for loop" is for reading a csv format file from = which I am
> extracting some information.

My crystal ball says that the 'for sy...' and 'for = sx...' loops are running
to completion, but you don't get the coordinates printed because you pu= t
them into the 'for l in f' loop which will only run once.

Is there any means by which I can run this= 'For l in f' loop again and again ? =A0

The quick and dirty fix is to replace

f =3D open(...)

in the code you are not showing with

f =3D=3D list(open(...))
=A0
f is just= a text file(csv format).. so why list ??
=A0
The reasonable thing to do is of course to move the preprocessing (e.g. csv= -
parsing) out of the sy and sx loops.

I did this but again then what I intend to do is not really happening, = For every pixel I read, =A0I want to traverse the full file, so that the in= formation I am taking from pixel have to match in one of the line in the fi= le. Can this be done by modifying my code ? or something new has to be devi= sed ?




--
http://mail.python.org/mailman/listinfo/python-list

--047d7b3a91e65c4ae104db4045e7--