0

Anyway, I'm still struggling with the task of 1) Calculating the eigenvalues and eigenvectors of a matrix, 2) Saving them to a file, 3) Loading the data back. I can do steps 1 and 2; but no matter what I try step 3 always throws an error. See np.savetxt triggers ValueError. Why? and Writing and Reading Eigenvalues & Eigenvectors, follow up

This time I tried saving the eigenvalues and eigenvectors separately, so they're both arrays. Unfortunately I still get the pickle error. Even when loading just the eigenvalues.

eigs=np.linalg.eig(P@K@P)
eigvals=np.real(eigs[0])
eigvecs=np.real(eigs[1])
np.savetxt('eigvals.txt',eigvals)
np.savetxt('eigvecs.txt',eigvecs)

Sure enough, eigvals and eigvecs show up as arrays, sizes 10000 and 10000x10000 respectively, in the Variable Explorer. And when I manually open eigvals.txt, I see a long list of floats as expected. But when I then try np.load('eigvals.txt','r'), I still get the pickle error (ValueError: Cannot load file containing pickled data when allow_pickle=False). What's wrong now?

Thanks

J.D.
  • 139
  • 4
  • 14
  • In terms of follow-up questions it's usually done by opening up new questions. This allows better search for other users. In general, each question though, should be [complete](https://stackoverflow.com/help/minimal-reproducible-example) (your example for example is nothing we can run to verify your problem; and you did not show the error you observe!). Also: why are you trying np.savetext and not np.save? Try to show some reproducible example. And whats wrong with [this](https://stackoverflow.com/a/57336601/2320035) answer? – sascha Aug 04 '19 at 07:58
  • Your first question belongs on [Meta StackOverflow](https://meta.stackoverflow.com/) – Him Aug 04 '19 at 08:05
  • If you turn this into one question, I will trade my down for an up. – Him Aug 04 '19 at 08:05
  • Sorry, didn't even know about Meta StackOverflow. First question removed. Ok, it looks like save should be paired with load, and savetxt with loadtxt, but not a mix-and-match. On another piece of advice, managed to get the data to load with savetxt and loadtxt. Thanks Unfortunately, when I tried to confirm the calculations using the equation Av=lambda v for a specific eigenvector/eigenvalue, they failed to match. Will see if I can reproduce this with a convenient-size matrix. – J.D. Aug 04 '19 at 08:27
  • What's this `Variable Explorer`? – hpaulj Aug 04 '19 at 09:52
  • It's a tab, next to File Explorer. Displays variables and their values on the top right of the screen, above the Console. – J.D. Aug 04 '19 at 10:42
  • @J.D. Are you using an IDE of some sort? `Variable Explorer` isn't native to python. – Him Aug 04 '19 at 10:45
  • When you respond directly to a comment, that poster does get a notification of your response. But they don't have to reply back - then, or later, or ever. This isn't a paid help-line. – hpaulj Aug 04 '19 at 16:06
  • I gave a small working example in my reply to your first question: https://stackoverflow.com/a/57336653/901925 – hpaulj Aug 04 '19 at 16:42

0 Answers0