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


Groups > comp.lang.python > #43830

Working with lists within Dictionaries

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 <insideshoes@gmail.com>
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 <insideshoes@gmail.com>
To "python-list@python.org" <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 <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.771.1366293499.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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:

<cvmat(type=42424010 8UC3 rows=3000 cols=3000 step=9000 )>

Traceback (most recent call last):
  File "C:\Users\inshu\Desktop\test_reading .py", line 27, in <module>
    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.

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


Thread

Working with lists within Dictionaries inshu chauhan <insideshoes@gmail.com> - 2013-04-18 19:28 +0530

csiph-web