0

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.

2
  • 1
    typically it helps if you provide some evidence of trying to solve your problem Commented Nov 17, 2020 at 21:28
  • you can use pickle standard library for doing this Commented Nov 17, 2020 at 21:30

1 Answer 1

2

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])

The docs can be found here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.