From: Francesc A. <fa...@py...> - 2004-10-11 12:35:48
|
A Diumenge 10 Octubre 2004 05:59, Shin, Daehyok va escriure: > Assuming at every simulation step I got a numeric array of 100 rows and 10 > cols, > what is the most efficient way to append it to Table? You can do something like: from numarray import * from tables import * class Cols(IsDescription): V1 = FloatCol(shape=10) f = openFile("test.hd5", "w") tab = f.createTable("/","Data",Cols,"Data") for i in range(10): # d simulates the output of your simulation step d = arange(i, 1000+i, shape=(100,10), type=Float64) tab.append([d]) f.close() i.e. declaring a column with dimension 10. > I want to use Table rather than EArray because of explicit column names. In that case, you can't use the recipe above. I would suggest you getting a numarray.records.RecArray object from every step of your simulation code. Then, you can feed the RecArray to Table.append() without any problem. By the way, after thinking a bit about passing lists of numarray/Numeric to the Table.append() method, I came to the conclusion that this is possible, although this use is meant for multidimensional columns. For example: from numarray import * from tables import * class Cols(IsDescription): V1 = FloatCol(shape=10) V2 = IntCol(shape=5) f = openFile("test2.hd5", "w") tab = f.createTable("/","Data",Cols,"Data") for i in range(10): # d simulates the output of your simulation step d = arange(i, 1000+i, shape=(100,10), type=Float64) e = arange(i, 500+i, shape=(100,5), type=Int32) tab.append([d, e]) f.close() works without problems. Maybe I should specify in the docs that you can use lists of Numeric/numarray objects *only* in case of multimensional columns. Cheers, -- Francesc Alted |