python - 在 python 中使用 zip 函数
问题描述
我将值保存在文件中:
[0. 0.5 1. 1.5 2. 2.5000002 .......] [1.00000000e+00 5.32289624e-01 3.31494868e-01 2.17292413e-01 1.46866933e-01 1.01670586e-01......]
但我希望将值保存为:
0.0 1.00000000e+00
0.5 5.32289624e-01
1.0 3.31494868e-01
1.5 2.17292413e-01
2.0 1.46866933e-01
2.5 1.01670586e-01
因此它可以很容易地在图表中绘制。
这是我的python代码部分:
time = hb_ac.solution['time']
results = hb_ac.solution['results']
tau = hb_ac.solution['tau']
fit=hb_ac.solution['fit']
estimate = hb_ac.solution['estimate']
with open('CaOw2.4dat', 'w') as out:
out.write("{time} {results}".format(time=time,results=results))
关于如何在此处使用 zip 功能以获得所需格式的输出的任何建议。
解决方案
这是你想要的?
time = range(10)
results = range(10,20)
with open('CaOw2.4dat', 'w') as out:
for t, result in zip(time, results):
out.write("{time} {results}\n".format(time=t,results=result))
文件内容:
0 10
1 11
2 12
3 13
4 14
5 15
6 16
7 17
8 18
9 19
推荐阅读
- html - 如何使文本出现在div内的悬停上?
- javascript - 根据嵌套类显示/隐藏表格行
- javascript - 如何从字符串中删除特定字符并在需要时将其放回
- php - Larvael Auth 中间件“非法偏移类型”
- tableau-api - 处理 Tableau 固定计算中的重复记录
- java - 如何以编程方式将 pkcs12 文件导入 Java 密钥库
- ios - 如何在swift中将标题视图添加到每个自定义tableViewCells
- oracle - 编写一个读取特定表并根据读取的表填充另一个表的函数
- python - 根据另一列(熊猫)中的值计算一列中的天数差异
- python - 使用来自 Confluent Kafka 主题的数据并使用 Python 退出