((x1,y1,z1),(x2,y2,z2),...)
End resulst
((x2-x1),(y2-y1),(z2-z1)),...
Thus far my strategy is to use the enumerate function to create a new array offset from the original array, and then subtract them.
Expand|Select|Wrap|Line Numbers
- #creates a list called dataList from and external coordinates file
- dataList = [[float(s) for s in item.strip().split(",")] for item in open("coordinates.txt").readlines()]
- #creates an empty new array
- new_array=[]
- #enumerates the list
- for i,points in enumerate(dataList):
- x,y,z = points
- x2,y2,z2 = dataList[i+1]
- new_array.append((x2-x, y2-y, z2-z))
- print new_array
File "C:\Python27\coordinate scheme.py", line 9, in <module>
x2,y2,z2 = dataList[i+1]
IndexError: list index out of range
I'm new at Python and especially workining with nested lists and am stuck on where to go from here.
Can you make recommendations on how to address this? Not really sure what list index out of range refers too.
Thanks