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

Date 2012-10-21 12:09 +0200
Subject a prob.. error in prog ..dont knw how to correct
From inshu chauhan <insideshoes@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2583.1350814179.27098.python-list@python.org> (permalink)

Show all headers | 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