May-18-2019, 02:49 PM
I'm new too python, would be glad if somebody could help me with my first Table.
My Code is the following:
But actually I am trying to save one Txt.-document which should look like the following Table:
My Code is the following:
import numpy as np import math import sys import argparse #print("Hallo world!") #print("\n") B = 0.30 # thickness m = 3 # numbers of Layer s = 5 # Steps for one Layer Z = 0.30 # Z-value z1= 0.30 z2= B*m i=1 # variable for Lines n=1 # Layer counter g=2 S_ges = s * m # lines in total while n<= m: for g in range(1,m, 1): I=np.linspace(i , S_ges , S_ges, dtype=int) table=np.zeros((S_ges, 3) ) # np.zeros(shape, dtype=float, order='C') table[:,0]=I table[:,1]=Z table[:,2]=n i +=1 print (table) n +=1 Z += B g +=n fmt = ['%i'] + 2 * ['%.3f'] np.savetxt("Loop.txt", table, fmt = fmt )The Output is the following:
Output:[[ 2. 0.3 1. ]
[ 2. 0.3 1. ]
[ 3. 0.3 1. ]
[ 4. 0.3 1. ]
[ 5. 0.3 1. ]
[ 6. 0.3 1. ]
[ 7. 0.3 1. ]
[ 8. 0.3 1. ]
[ 9. 0.3 1. ]
[10. 0.3 1. ]
[11. 0.3 1. ]
[12. 0.3 1. ]
[13. 0.3 1. ]
[14. 0.3 1. ]
[15. 0.3 1. ]]
[[ 4. 0.6 2. ]
[ 4. 0.6 2. ]
[ 5. 0.6 2. ]
[ 6. 0.6 2. ]
[ 7. 0.6 2. ]
[ 7. 0.6 2. ]
[ 8. 0.6 2. ]
[ 9. 0.6 2. ]
[10. 0.6 2. ]
[11. 0.6 2. ]
[11. 0.6 2. ]
[12. 0.6 2. ]
[13. 0.6 2. ]
[14. 0.6 2. ]
[15. 0.6 2. ]]
[[ 6. 0.9 3. ]
[ 6. 0.9 3. ]
[ 7. 0.9 3. ]
[ 7. 0.9 3. ]
[ 8. 0.9 3. ]
[ 9. 0.9 3. ]
[ 9. 0.9 3. ]
[10. 0.9 3. ]
[11. 0.9 3. ]
[11. 0.9 3. ]
[12. 0.9 3. ]
[13. 0.9 3. ]
[13. 0.9 3. ]
[14. 0.9 3. ]
[15. 0.9 3. ]]
The Output the Txt.-document is only the following:Output:6 0.900 3.000
6 0.900 3.000
7 0.900 3.000
7 0.900 3.000
8 0.900 3.000
9 0.900 3.000
9 0.900 3.000
10 0.900 3.000
11 0.900 3.000
11 0.900 3.000
12 0.900 3.000
13 0.900 3.000
13 0.900 3.000
14 0.900 3.000
15 0.900 3.000
But actually I am trying to save one Txt.-document which should look like the following Table:

Output: 1 0.3 1.
2 0.3 1.
3 0.3 1.
4 0.3 1.
5 0.3 1.
6 0.3 1.
7 0.3 1.
8 0.3 1.
9 0.3 1.
10 0.3 1.
11 0.3 1.
12 0.3 1.
13 0.3 1.
14 0.3 1.
15 0.3 1.
16 0.6 2.
17 0.6 2.
18 0.6 2.
19 0.6 2.
20 0.6 2.
21 0.6 2.
22 0.6 2.
23 0.6 2.
24 0.6 2.
25 0.6 2.
26 0.6 2.
27 0.6 2.
28 0.6 2.
29 0.6 2.
30 0.6 2.
31 0.9 3.
32 0.9 3.
33 0.9 3.
34 0.9 3.
35 0.9 3.
36 0.9 3.
37 0.9 3.
38 0.9 3.
39 0.9 3.
40 0.9 3.
41 0.9 3.
42 0.9 3.
43 0.9 3.
44 0.9 3.