Trying to save numpy into a new txt file. I've got the amount, average, min and max. I'm now trying to save those numbers into a new txt file. I'm new to numpy and python, so this might be an easy question.
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()
I want the new txt file to have this format:
Amount:
Average:
Max:
Min:
You can try
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.