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


Groups > comp.lang.python > #31843

a prob.. error in prog ..dont knw how to correct

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; '__name__': 0.07; 'data:': 0.07; 'python': 0.09; '22,': 0.09; 'received:mail-qc0-f174.google.com': 0.09; 'skip:r 60': 0.09; 'tuple.': 0.09; 'typeerror:': 0.09; 'def': 0.10; 'subject:error': 0.11; "'__main__':": 0.16; 'add,': 0.16; 'dist': 0.16; 'dot,': 0.16; 'numpy': 0.16; 'prog': 0.16; 'sorting': 0.16; 'subject: ..': 0.16; 'math': 0.20; 'skip:" 30': 0.20; 'trying': 0.21; 'import': 0.21; 'tried': 0.25; 'skip:[ 10': 0.26; '(most': 0.27; 'message- id:@mail.gmail.com': 0.27; 'correct': 0.28; 'array': 0.29; 'points': 0.29; "skip:' 10": 0.30; 'error': 0.30; 'point': 0.31; 'file': 0.32; 'print': 0.32; 'getting': 0.33; '11,': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'unable': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'data': 0.37; 'object': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'distance': 0.62; 'solve': 0.62; 'between': 0.63; 'floor,': 0.65; 'stuck': 0.65; 'co-ordinates': 0.84; 'min': 0.84; 'subject:.. ': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=2iPVIC1VWR17e5KCErN3lIBzvf9+aPokFLlDn0/SZ0k=; b=r2o5tf7lK8yXMb0M8BJowo8DBNdeEeee7GCo555mue4GSW6SpQLuRmvcv3641sN0+0 2o2qj3O4Zs6J1+QIkSuRgqTpKy9SJHrCWHSetU5wTh6uIDTSKKH1x8vom38BALZkmywD nQC6zlUXdbQ27ULXpLrGekxuLx23ZeuUaB65NFnqt4xgxRc6Rr3vzwk4e98JtYEo3gbk yDju8q/QLZTb6VmijM4hzucbRZJTiiFRFc35V1fKCk/38iY70cr/XZRxnPSuJnIVvEsj nOLhaE5//hradc2mqcbe24yq7Is6QU57K6UJbSXZ91cDSfhAALfRvchaPU9fWvCo+Cxn kPqw==
MIME-Version 1.0
Date Sun, 21 Oct 2012 12:09:36 +0200
Subject a prob.. error in prog ..dont knw how to correct
From inshu chauhan <insideshoes@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.2583.1350814179.27098.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350814179 news.xs4all.nl 6902 [2001:888:2000:d::a6]:45090
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31843

Show key headers only | View raw


I am new to python and have a little problem to solve .. i have an
array with x, y, z co-ordinates in it as a tuple. I am trying to find
the distance between each point and sorting the points according to
the min distance.. i have tried a prog but m stuck bcoz of this error
which I am unable to correct



import cv
from math import floor, sqrt, ceil
from numpy import array, dot, subtract, add, linalg as lin

def calcdist(data):
    for p in data:
        x = p[0]
        y = p[1]
        z = p[2]
    for i in range(len(data)):
      dist = sqrt((x[i]-x[i+1])**2 + (y[i]-y[i+1])**2 +(z[i]-z[i+1]**2))
      return dist


def ReadPointCloud(filename):
    return [tuple(map(float, l.split()[1:4])) for l in open(filename)]

def main (data):

    for i in range(len(data)): # Finding Neighbours
       for j in range(len(data)):
          dist = calcdist(data)
          print dist


if __name__ == '__main__':
    data = ReadPointCloud(r'C:\Thesis\NEHreflectance_Scanner_1_part.txt')
    data = data[0:100]
    main(data)






the error m getting is...




Traceback (most recent call last):
  File "C:\Users\inshu\Desktop\cal-dist.py", line 29, in <module>
    main(data)
  File "C:\Users\inshu\Desktop\cal-dist.py", line 22, in main
    dist = calcdist(data)
  File "C:\Users\inshu\Desktop\cal-dist.py", line 11, in calcdist
    dist = sqrt((x[i]-x[i+1])**2 + (y[i]-y[i+1])**2 +(z[i]-z[i+1]**2))
TypeError: 'float' object has no attribute '__getitem__'

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


Thread

a prob.. error in prog ..dont knw how to correct inshu chauhan <insideshoes@gmail.com> - 2012-10-21 12:09 +0200
  Re: a prob.. error in prog ..dont knw how to correct Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-10-21 14:55 +0300

csiph-web