Reputation: 79
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:
Upvotes: 0
Views: 30
Reputation: 1690
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()
Upvotes: 1