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__' -- http://mail.python.org/mailman/listinfo/python-list