title: Writing and reading complex numbers using numpy.savetxt and numpy.loadtxt
body: <p>I need to write and read complex numbers. I would like to use <code>numpy.savetxt</code> and <code>numpy.loadtxt</code> to do so. Since the code that I have written is rather big I created a test file to try to write and read complex numbers.</p>
  
  <p>So far I have been able to write complex numbers using <code>numpy.savetxt</code>. The code is the following:</p>
  
  <pre><code>import numpy
  
  d1 = -0.240921619563 - 0.0303165074169j
  d2 = -0.340921619563 - 0.0403165074169j
  d3 = -0.440921619563 - 0.0503165074169j
  d4 = -0.540921619563 - 0.0603165074169j
  
  array = numpy.array([d1, d2, d3, d4])
  
  save = open("test.dat", "w")
  numpy.savetxt(save, array.reshape(1, array.shape[0]), newline = "\r\n", fmt = "%.10f")
  
  save.close()
  </code></pre>
  
  <p>This gives the following output:</p>
  
  <pre><code> (-0.2409216196+-0.0303165074j)  (-0.3409216196+-0.0403165074j)  (-0.4409216196+-0.0503165074j)  (-0.5409216196+-0.0603165074j)
  </code></pre>
  
  <p>All that I now want to be able to do is actually read/load the data. The script I have is:</p>
  
  <pre><code>import numpy
  
  d = numpy.loadtxt("test.dat")
  </code></pre>
  
  <p>This piece of code is not sufficient and I am currently unable to load the data. My problem is similar to <a href="https://stackoverflow.com/questions/23121271/numpy-read-complex-numbers-from-text-file">this one</a>. However, by manually replacing the <code>+-</code> by a <code>-</code> I am still unable to load the data. I think the solution lies in the <code>dtype</code> option for <code>numpy.loadtxt</code>. I have not been able to figure it out though.</p>
  
  <p>Your help is greatly appreciated!</p>