【发布时间】:2020-11-26 13:53:49
【问题描述】:
我正在运行一个循环来计算 abs(x-y) 的 n 试验
我的代码:
for i in P0:
answer = (i['x']-i['y'])
A = (abs(answer))
返回 P0 的值
P0是第一次试验的位置数据(P0 = T0['positions'])。
有没有一种方法可以使用嵌套循环遍历所有轨迹 (Tn) 的所有位置 (Pn)?
T type - list, of all the trails
Tn type - dict of the 1st trial
P type - list, of the positions (x,y) coordinates
Pn type - list
我试过了:
for i in T:
Ti = T[i]
Pi = Ti['positions']
for i in Pi:
answer = (i['x']-i['y'])
A = (abs(answer))
但我得到了错误:
TypeError: list indices must be integers or slices, not dict.
由于我不熟悉使用 dict 数据类型,有什么方法可以完成这项工作
谢谢
【问题讨论】:
-
不是很清楚你想要什么,能否提供样本数据?
标签: python numpy for-loop statistics nested-loops