Problem Table Output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem Table Output (/thread-18450.html) |
Problem Table Output - Phil - May-18-2019 I'm new too python, would be glad if somebody could help me with my first 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: The Output the Txt.-document is only the following:
But actually I am trying to save one Txt.-document which should look like the following Table:
RE: Problem Table Output - michalmonday - May-18-2019 It's kind of difficult to work with it without relating these variables to real life objects (or maybe I'm just noob:P) so it's not improved as much as it could be... But it generates the output you showed (including additional 45th row that yours' didn't have) 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 total_S_ges = S_ges accumulated_i = 0 whole_table = np.zeros([0, 3]) # 3 columns, 0 rows while n<= m: #for g in range(1, m, 1): I = np.linspace(i , total_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 whole_table = np.concatenate((whole_table, table), axis=0) #i +=1 n += 1 Z += B g += n # added lines i += S_ges total_S_ges += S_ges print(whole_table) fmt = ['%i'] + 2 * ['%.3f'] np.savetxt("Loop.txt", whole_table, fmt = fmt )
RE: Problem Table Output - Phil - May-18-2019 @michalmonday Thanks a Lot for the help! Actually it helped me a lot. That what i was looking for. With that i can go on with the table. RE: Problem Table Output - michalmonday - May-18-2019 Btw I made silly mistake and just modified the code by deleting this line: i +=1 Otherwise the output didn't print number "16" and printed 2 number "17"s instead etc. Nice that I could help:) RE: Problem Table Output - Phil - May-19-2019 For the first Columns it is already working very well. so actually i have it like this now: import numpy as np import math import sys import argparse B = 0.30 # Layer thickness # inputdata m = 3 # numbers of Layer s = 10 # Steps for one Layer Z = 0.30 # Z-value z1= 0.30 z2= B*m i=1 # variable for Lines n=1 # Layer counter Typ = 0 L1_max = 2 L1_Step = L1_max/s S_2 = s whole_table = np.zeros([0, 5]) # 3 columns, 0 rows while n<= m: #for g in range(1, m, 1): I = np.linspace(i , S_2 , s, dtype=int) # L1 = np.linspace(0 , L1_max, s) #?? #L1 = np.linspace(2 , -L1_max, s) #?? L1 = np.linspace(-2 , +L1_max, s) table = np.zeros((s, 5) ) # np.zeros(shape, dtype=float, order='C') table[:,0] = I table[:,1] = Z table[:,2] = L1 table[:,3] = n table[:,4] = Typ whole_table = np.concatenate( (whole_table, table), axis=0) n += 1 Z += B # added lines i += s S_2 += s print(whole_table) fmt = ['%i'] + ['%.1f'] + ['%.4f'] + ['%i'] * 2 np.savetxt("Loop.txt", whole_table, fmt = fmt )Output: But the third column seems to be a little bit more difficult.Do you have an Idea here? I would like to have the possibility to count in this column from o tu L_max and than to -L_max. So should look like this:
|