【发布时间】:2015-04-11 14:11:48
【问题描述】:
我有这样的代码:
nList = [[[0,0,0],[100420,0,623400]],\
[[]],\
[[100043,1324000,123240]],\
[[0,0,543],[3002340,443000,34300],[334000,4043400,7342],[0,0,134020]]
import math
prevX, prevY, prevT = 0, 0, 0
#Entry point
for traceIndex in range(0, len(nList)):
print 'trace: ' + str(traceIndex+1)
trace = nList[traceIndex]
for pointIndex in range(0, len(trace)):
point = trace[pointIndex]
if len(point)>0:
tempX, tempY, tempT = point[0], point[1], point[2]
if pointIndex != 0:
#calculate time difference here
timeDiff = calculateTime (tempT,prevT)
基本上,nList 在每个 \ 之前都有子列表,称为跟踪,每个跟踪都有三个元素的点。例如,nList[0][0] 产生跟踪 1,点 1=[0,0,0]。 point=[x-coordinate, y-coordinate, time]。我已经计算了每个跟踪中每个点的 timeDiff。现在我需要总结不同轨迹的 timeDiff 并打印出来:
trace: 1
623400
trace: 2
trace: 3
trace: 4
187393
nList 由称为“trace”的子列表组成,每个“trace”都有一个或多个点,其中包含 3 个元素 [x, y, t]。例如,trace1 有 2 个点,因此 trace1point1 = [0,0,0] 和 trace1point2=[100420,0,623400]。 timeDiff 计算 t2 和 t1 之间的差异。对于 trace1,这将是 (623400-0)。与跟踪 1 相比,跟踪 4 有更多的点,timeDiff 将用于具有 1=<N=<4、(34300-543)、(7342-34300) 和 (134020-7342) 的单个 trace4pointN。我想编写一个程序,获取每个跟踪中的所有 timeDiff,并以产生上述输出的方式对它们进行汇总。
【问题讨论】:
-
什么是
timeDiff?你说你想“总结不同轨迹的 timeDiff”。你想总结哪个timeDiffs?不止一个吗?什么是“trace4 输出”?它“本质上”是什么意思是什么?什么是“轨迹中的 3 坐标点”?什么是“第三要素的个体差异”? -
nList 由称为“trace”的子列表组成,每个“trace”都有一个或多个带有 3 个元素 [x, y, t] 的点。例如,trace1 有 2 个点,因此 trace1point1 = [0,0,0] 和 trace1point2=[100420,0,623400]。 timeDiff 计算 t2 和 t1 之间的差异。对于 trace1,这将是 (623400-0)。与轨迹 1 相比,轨迹 4 具有更多点,而 timeDiff 将针对单个轨迹 4 点 N,其中 1=
标签: python function python-2.7 for-loop printing