1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| >>> import numpy as np
>>> x = np.arange(10)
>>> y = np.sin(np.pi*x/10)
>>> x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> y
array([ 0. , 0.30901699, 0.58778525, 0.80901699, 0.95105652,
1. , 0.95105652, 0.80901699, 0.58778525, 0.30901699])
>>> data = np.array([x, y]).transpose()
>>> data
array([[ 0. , 0. ],
[ 1. , 0.30901699],
[ 2. , 0.58778525],
[ 3. , 0.80901699],
[ 4. , 0.95105652],
[ 5. , 1. ],
[ 6. , 0.95105652],
[ 7. , 0.80901699],
[ 8. , 0.58778525],
[ 9. , 0.30901699]])
>>> np.savetxt('tmp/test.dat', data)
>>> np.loadtxt('tmp/test.dat')
array([[ 0. , 0. ],
[ 1. , 0.30901699],
[ 2. , 0.58778525],
[ 3. , 0.80901699],
[ 4. , 0.95105652],
[ 5. , 1. ],
[ 6. , 0.95105652],
[ 7. , 0.80901699],
[ 8. , 0.58778525],
[ 9. , 0.30901699]]) |
Partager