I have a for loop that generates several variables let say a
, b
, and c
. I would like to
vertically stack the variables after the for loop gone trough the loops. Here what I would like to do. (let say the variables are just numbers (1,2,3) for sake of example).
from astropy.table import Table
N1 = 3
N2 = 5
a = zeros((N2,N1))
b = zeros((N2,N1))
c = zeros((N2,N1))
for i in range(N2):
a[i] = range(N1)
b[i] = range(N1)
c[i] = range(N1)
t = Table([a[i], b[i], c[i]], names=('a', 'b', 'c'), meta={'name': 'first table'})
at the moment when I print t
I get
a b c
--- --- ---
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
What I want to get is the following;
a b c
--- --- ---
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
Thank you very much for your help.
If you want for instance the number of rows repeat n=5 times you just need to use vstack
, similar to numpy.vstack
as following:
>>>from astropy.table import vstack
>>>t1=vstack([t,t,t,t,t])
>>>print t1
a b c
--- --- ---
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0
0.0 0.0 0.0
1.0 1.0 1.0
2.0 2.0 2.0