python3-numpy: Appending to a file using numpy savetxt

后端 未结 1 747
误落风尘
误落风尘 2020-12-03 04:11

I am trying to append data to a file using numpy\'s savetxt function. Below is the minimum working example

#!/usr/bin/env python3
import numpy as np
f=open(\         


        
相关标签:
1条回答
  • 2020-12-03 04:49

    You should open file by binary mode.

    #!/usr/bin/env python3
    import numpy as np        
    f=open('asd.dat','ab')
    for iind in range(4):
        a=np.random.rand(10,10)
        np.savetxt(f,a)
    f.close()
    

    reference: python - How to write a numpy array to a csv file? - Stack Overflow How to write a numpy array to a csv file?

    0 讨论(0)
提交回复
热议问题