Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'else:': 0.03; 'indices': 0.07; 'advance': 0.07; '"__main__":': 0.09; 'blue': 0.09; 'data):': 0.09; 'pixels': 0.09; 'suggestions.': 0.09; 'def': 0.12; '65536': 0.16; 'data)': 0.16; 'dict': 0.16; 'dictionaries': 0.16; 'dictionary.': 0.16; 'integer.': 0.16; 'integers,': 0.16; 'tuple': 0.16; 'tuple,': 0.16; 'typeerror:': 0.16; 'trying': 0.19; 'everyone,': 0.19; '8bit%:5': 0.22; 'import': 0.22; 'to:name :python-list@python.org': 0.22; 'print': 0.22; 'error': 0.23; 'together.': 0.24; 'skip:" 30': 0.26; 'point': 0.28; 'points': 0.29; '8bit%:3': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; 'file': 0.32; 'lists': 0.32; '(most': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'should': 0.36; 'list': 0.37; 'skip:& 10': 0.38; '8bit%:4': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'how': 0.40; 'skip:c 50': 0.60; 'skip:t 30': 0.61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=KnEa0SL1bhHTB5h2X0M8zg5rZlZM1EE8o2wzQjdD1S8=; b=yP7gVcfuK7W62D1LPVt2XTTUG2nvM6dL56x271blFkZYLwyx4Y7ucnVa3+C2HpJRbe Cao78QgjJhyYPgjGUq5Ekb0i5dI2A8vsmgUkxWhFCS/XpejF4oE490J+ZF0sjqnY1DGb /Yv+BYXv6VawzO0Qf5s+g9mfU47nYNDHHtw1jAcecqc5ZY96Jhf9BKBXnNv94Oe5DLAV iUvVt/hdTBAbmPF9JBB5MT6OfFpQ0F4LUKmiPJ7SLpwT3bZelnrJYtRmxQUyg/chEtGY IYtSG4z3KzvK5nwXLP6Q6OefcFUH6/gPPWwSYwMi6lYKOUxQ0afIfpSlPefiP8BAxw/L LsJA== MIME-Version: 1.0 X-Received: by 10.50.33.11 with SMTP id n11mr3921037igi.40.1366293496934; Thu, 18 Apr 2013 06:58:16 -0700 (PDT) Date: Thu, 18 Apr 2013 19:28:16 +0530 Subject: Working with lists within Dictionaries From: inshu chauhan To: "python-list@python.org" Content-Type: multipart/alternative; boundary=089e0153873e8b91f104daa2fecf 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: 109 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366293499 news.xs4all.nl 2168 [2001:888:2000:d::a6]:47674 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43830 --089e0153873e8b91f104daa2fecf Content-Type: text/plain; charset=ISO-8859-1 Hello Everyone, I am trying to work with lists and dictionaries together. In the following code I have to access pixels in a segmented image through a dictionary. But the problem is when I am trying to update the list through dict it is giving me this error of tuple, ofcourse because list indices should be integer. THE CODE IS : import cv def access_segments(segimage, data): print segimage segments = {} for y in xrange(0, segimage.height): for x in xrange(0, segimage.width): if segimage[y,x] == (0.0, 0.0, 0.0): continue else: seg_color = segimage[y,x] blue = int(seg_color[0]) green = int(seg_color[1]) red = int(seg_color[2]) reg_num = blue + 256 * green + 65536 * red point = data[y,x] segments.setdefault(reg_num, [])[point] += point for p in sorted(segments.iterkeys()): points = (segments[p]) print len(points) print points if __name__== "__main__": data = cv.Load(r"C:\Users\inshu\Desktop\Masters Thesis\data\xyz_00000.yml") segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters Thesis\Segmentation\segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED) access_segments(segimage, data) THE ERROR IS: Traceback (most recent call last): File "C:\Users\inshu\Desktop\test_reading .py", line 27, in access_segments(segimage, data) File "C:\Users\inshu\Desktop\test_reading .py", line 16, in access_segments segments.setdefault(reg_num, [])[point] += point TypeError: list indices must be integers, not tuple How can I access the data without getting this error ? the points have x, y, z co-ordinates. Thanks In Advance for your suggestions. --089e0153873e8b91f104daa2fecf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hello Everyone,=A0

I am trying to= work with lists and dictionaries together.=A0
In the follo= wing code I have to access pixels in a segmented image through a dictionary= . But the problem is when I am trying to update the list through dict it is= giving me this error of tuple, ofcourse because list indices should be int= eger.=A0

THE CODE IS :
import c= v
def access_segments(segimage, data):
=A0 =A0 print se= gimage
=A0 =A0 segments =3D {}
=A0 =A0 for y in xrange(= 0, segimage.height):
=A0 =A0 =A0 =A0 for x in xrange(0, segimage.width):
=A0 =A0 = =A0 =A0 =A0 =A0 if segimage[y,x] =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[y,x]
=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 point =3D data[y,x]
=A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 segments.setdefault(reg_num, [])[point] +=3D point<= /div>
=A0 =A0 =A0 =A0 =A0 =A0=A0
=A0 =A0 for p in sorted(segm= ents.iterkeys()):
=A0 =A0 =A0 =A0 points =3D (segments[p])
=A0 =A0 =A0 =A0 print len(points)
=A0 =A0 =A0 =A0 print poin= ts

if __name__=3D=3D "__main__":
=A0 =A0 data =3D cv.Load(r"C:\Users\inshu\Desktop\Masters Thesis\da= ta\xyz_00000.yml")
=A0 =A0 segimage =3D cv.LoadImageM(r"C:\Users\inshu\Desktop\Maste= rs Thesis\Segmentation\segmentation_numbers_00000.tif", cv.CV_LOAD_IMA= GE_UNCHANGED)
=A0 =A0 access_segments(segimage, data)
= =A0 =A0=A0

THE ERROR IS:

<cvmat(type=3D42424010 8UC3 rows=3D3000 cols=3D3000 step=3D9000 )= >

Traceback (most recent call last):
= =A0 File "C:\Users\inshu\Desktop\test_reading .py", line 27, in &= lt;module>
=A0 =A0 access_segments(segimage, data)
=A0 File "C:\Us= ers\inshu\Desktop\test_reading .py", line 16, in access_segments
=
=A0 =A0 segments.setdefault(reg_num, [])[point] +=3D point
T= ypeError: list indices must be integers, not tuple

How can I access the data without get= ting this error ? the points have x, y, z co-ordinates.
Thanks In Advance for your suggestions.=A0
--089e0153873e8b91f104daa2fecf--