[英]Saving numpy into a text file
試圖將 numpy 保存到一個新的 txt 文件中。 我有數量,平均值,最小值和最大值。 我現在試圖將這些數字保存到一個新的 txt 文件中。 我是 numpy 和 python 的新手,所以這可能是一個簡單的問題。
import numpy as np
def main():
x = np.loadtxt("wind_readings.txt")
print("There are", len(x), "")
print('Average:', np.average(x))
print('Max:', np.amax(x))
print('Min:', np.amin(x))
main()
我希望新的 txt 文件具有以下格式:
數量:
平均數:
最大限度:
最小值:
你可以試試
file = open("testfile.txt","w")
file.write(f"Amount: {len(x)}\n")
file.write(f"Average: {np.average(x)}\n")
file.write(f"Max: {np.amax(x)}\n")
file.write(f"Min: {np.amin(x)}\n")
file.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.