So I have my two arrays and need to write them to a file called 'output.dat' such that I could then read the data from each array in that file and plot the data with pyplot.
-
1typically it helps if you provide some evidence of trying to solve your problemM Z– M Z2020-11-17 21:28:51 +00:00Commented Nov 17, 2020 at 21:28
-
you can use pickle standard library for doing thisAmir reza Riahi– Amir reza Riahi2020-11-17 21:30:04 +00:00Commented Nov 17, 2020 at 21:30
Add a comment
|
1 Answer
The numpy.save() function can be used to store the file, as:
x = np.array([1, 2, 3, 4])
# Note: The standard convention is to store as a .npy file.
with open('output.dat', 'wb') as f:
np.save(f, x)
The numpy.load() function can be used to retrieve the file, as:
with open('output.dat', 'rb') as f:
x = np.load(f)
>>> array([1, 2, 3, 4])