3

I have used numpy to save a matrix of complex numbers. The output file looks like that:

(1.100412357301083777e-02+1.471303433818593742e-02j)     (1.511426586599529109e-02+-2.516143258497194335e-03j)   
(1.084202636262432407e-02+1.438252996657629623e-02j)     (1.447620213198375083e-02+4.471111098343749646e-03j)    

Now, I tried reading it in using numpy data = np.loadtxt('PsiPfree1.out', delimiter='\t', dtype=np.complex128), but I get the following error:

items = [conv(val) for (conv, val) in zip(converters, vals)]  
ValueError: complex() arg is a malformed string`

Any ideas how I could get this to work?

Edit: I now also tried without the parenthesis making the matrix look like this:

1.100412357301083777e-02+1.471303433818593742e-02j  1.511426586599529109e-02+-2.516143258497194335e-03j
1.084202636262432407e-02+1.438252996657629623e-02j  1.447620213198375083e-02+4.471111098343749646e-03j

This results in the same issue.

12
  • That's probably cause of the parentheses. Get rid of those first Commented Apr 16, 2014 at 22:28
  • I tried by replacing with spaces. Exactly the same error. Commented Apr 16, 2014 at 22:29
  • Don't use any spaces/parentheses/commas/squiggly lines. The delimiter between your values should be the string you're specifying as the delimiter, and that string only. Commented Apr 16, 2014 at 22:32
  • 1
    You seem to have a typo in the second column, first row. Is the +- intentional? Commented Apr 16, 2014 at 22:46
  • 1
    See also: stackoverflow.com/questions/21012484/… Commented Apr 22, 2014 at 23:04

1 Answer 1

1

The problem is, that the numpy savetxt function np.savetxt('PsiPges.out',PsiPges , delimiter='\t') I used exports the data matrix, but for all negative imaginary parts it writes +- (see matrix posted above). If this is replaced by - only, the loadtxt function works correctly.

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

2 Comments

Oh, ok. I thought you were fixing the problem by simply removing the minus, which would have given you wrong values.
;) No. Thank you for your time! I wouöld never have found that.

Your Answer

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