How to save and load an array of complex numbers using numpy.savetxt?

后端 未结 2 506
轮回少年
轮回少年 2021-02-05 11:00

I want to use numpy.savetxt() to save an array of complex numbers to a text file. Problems:

  • If you save the complex array with the default format string, the imagi
2条回答
  •  孤独总比滥情好
    2021-02-05 11:16

    Here's my solution, in case anybody hits this question from Google.

    Saving:

    numpy.savetxt('outfile.txt', numpy.column_stack([array.real, array.imag]))
    

    Loading:

    array_real, array_imag = numpy.loadtxt('outfile.txt', unpack=True)
    array = array_real + 1j * array_imag
    

    I will still award the checkmark to a better solution!

提交回复
热议问题