Thu, 15 Jul 2010 20:00:09 -0400, David Warde-Farley wrote: > (CCing NumPy-discussion where this really belongs) > > On 2010-07-08, at 1:34 PM, cfra...@uci.edu wrote: > >> Need Complex numbers in the saved file. > > Ack, this has come up several times according to list archives and no > one's been able to provide a real answer. > > It seems that there is nearly no formatting support for complex numbers > in Python. for a single value, "{0.real:.18e}{0.imag:+.18e}".format(val) > will get the job done, but because of the way numpy.savetxt creates its > format string this isn't a trivial fix. > > Anyone else have ideas on how complex number format strings can be > elegantly incorporated in savetxt?
The bug here is that >>> z = np.complex64(1+2j) >>> '%.18e' % z '1.000000000000000000e+00' >>> float(np.complex64(1+2j)) 1.0 This should raise an exception. I guess the culprit is at scalarmathmodule.c.src:1023. It should at least be changed to raise a ComplexWarning, which we now anyway do in casting. -- Pauli Virtanen _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion