[SciPy-User] Saving into file.txt
Oleksandr Huziy
guziy.sasha at gmail.com
Mon Apr 14 06:42:45 EDT 2014
Transposing the array does the trick:
In [1]: import numpy as np
In [2]: x = np.arange(10)
In [3]: y = np.random.randn(10)
In [4]: y
Out[4]:
array([ 0.77039544, 1.27781447, 0.96214621, -0.04514849, 0.12023634,
0.33786337, -0.88450054, -0.67355859, 2.11181118, 0.96484793])
In [5]: x
Out[5]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [9]: np.savetxt("test.txt", [x, y])
In [10]: cat test.txt
0.000000000000000000e+00 1.000000000000000000e+00 2.000000000000000000e+00
3.000000000000000000e+00 4.000000000000000000e+00 5.000000000000000000e+00
6.000000000000000000e+00 7.000000000000000000e+00 8.000000000000000000e+00
9.000000000000000000e+00
7.703954403007949869e-01 1.277814469462716263e+00 9.621462065528501029e-01
-4.514849461497021099e-02 1.202363398274446937e-01 3.378633716328510173e-01
-8.845005407517207985e-01 -6.735585891743005593e-01
2.111811179340500555e+00 9.648479328801105037e-01
In [11]: np.savetxt("test.txt", np.asarray([x, y]).T)
In [12]: cat test.txt
0.000000000000000000e+00 7.703954403007949869e-01
1.000000000000000000e+00 1.277814469462716263e+00
2.000000000000000000e+00 9.621462065528501029e-01
3.000000000000000000e+00 -4.514849461497021099e-02
4.000000000000000000e+00 1.202363398274446937e-01
5.000000000000000000e+00 3.378633716328510173e-01
6.000000000000000000e+00 -8.845005407517207985e-01
7.000000000000000000e+00 -6.735585891743005593e-01
8.000000000000000000e+00 2.111811179340500555e+00
9.000000000000000000e+00 9.648479328801105037e-01
Cheers
2014-04-14 6:28 GMT-04:00 Antonelli Maria Rosaria <
maria-rosaria.antonelli at curie.fr>:
> Hi,
>
> I need to save same data arrays into a file.txt.
> I would like to save them as different columns.
> At the moment I can manage to save them as different lines.
>
>
> Can you please give me some hints ?
> Best regards,
> Rosa
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
--
Sasha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140414/574ce2f8/attachment.html>
More information about the SciPy-User
mailing list