我有一个像这样的文件
--------------Time step: 1 ---------------
Accumulated rewards: 1.5
Alpha: 660
Beta: 173
TCP_Friendliness: 1
Fast_Convergence: 1
State: 3
Retries: 0.0
---------------------------------------------------------------
---------------Time step: 2 ---------------
Accumulated rewards: 2.724744871391589
Alpha: 193
Beta: 0
TCP_Friendliness: 0
Fast_Convergence: 0
State: 3
Retries: 0.0
---------------------------------------------------------------
---------------Time step: 3 ---------------
Accumulated rewards: 3.869459113944921
我想将时间步长值提取到一个X数组中,将累计奖励值提取到一个Y数组中,我不知道如何做,因为我有0个python经验,但这是我编写的初始循环,它跳过了示例中未包含的前几行(胡言乱语数据)
with open('Tuner_result_1.txt') as f:
for _ in range(11):
next(f)
for line in f:
x = [line.split()[0]]
y = [line.split()[1]]
显然,第二个for中的操作是不正确的,我不知道如何以我想要的方式正确地阅读我想要的行
输出:
可以应用下一个正则表达式:^{}
代码:
您可以分别处理每个匹配:
也可以使用字符串切片:
相关问题 更多 >
编程相关推荐