A Wednesday 04 June 2008, escriguéreu: > I guess my problem is to replace an array with totally a different > array. The slicing notation works well for replacing the data in the > existing array. In my case, I need to "redefine" the array. I tried > to do something like this and it doesn't set newData into the file > (which I can understand): > > datArray = file.root.mygroup.myarray > newData = some-arbitrary-array > datArray = newData > > But something like this would work: > datArray[0] = [1,2,3] (if size matches) > > I feel I will have to delete and recreate the array with the new > data, but then I will need to copy the attributes of datArray as > well.
Yes, in that case deleting and recreating the array may be your best approach. However, have in mind that the EArray class allows to increase (.append() method) and decrease (.truncate()) the enlargeable dimension. But, unless you are dealing with very large arrays, this should be more work than completely removing and recreating the leaves. Cheers, > > Thanks for the help, and I learned a lot in this process. > > Jianfu > > On Tue, Jun 3, 2008 at 3:02 AM, Francesc Alted <[EMAIL PROTECTED]> wrote: > > [Please write to the PyTables list from a subscribed address. If > > not, your messages will not be injected.] > > > > A Tuesday 03 June 2008, escriguéreu: > > > Thanks! I'll digest that information, which appears to be > > > complicated. I was looking for a simple call to reset arrays of > > > certain dimensions (shape is a variable) that are not fixed > > > dimensions. I may consider recreating the array, and my only > > > concern is to recreate the attributes of the existing array. > > > > Oh, it is not so complicated, really: it's just a matter to be used > > to the extended slicing notation: > > > > http://www.informit.com/articles/article.aspx?p=453682&seqNum=6 > > [you can go directly to the extended slicing part, but a complete > > read is recommended] > > > > Here it is a simple example for a CArray (but this works for every > > PyTables Leaf instance): > > > > In [4]: test = f.createCArray(f.root, "test", tables.Float32Atom(), > > (2,10)) > > > > In [5]: test[:] > > Out[5]: > > array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], > > [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], > > dtype=float32) > > > > In [17]: test[0, 0:5] = 1 > > > > In [18]: test[:] > > Out[18]: > > array([[ 1., 1., 1., 1., 1., 0., 0., 0., 0., 0.], > > [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], > > dtype=float32) > > > > In [19]: test[1, 5:10] = 1 > > > > In [20]: test[:] > > Out[20]: > > array([[ 1., 1., 1., 1., 1., 0., 0., 0., 0., 0.], > > [ 0., 0., 0., 0., 0., 1., 1., 1., 1., 1.]], > > dtype=float32) > > > > In [23]: test[:, 3:7] = 2 > > > > In [24]: test[:] > > Out[24]: > > array([[ 1., 1., 1., 2., 2., 2., 2., 0., 0., 0.], > > [ 0., 0., 0., 2., 2., 2., 2., 1., 1., 1.]], > > dtype=float32) > > > > In [25]: test[:, 1:10:3] = 3 > > > > In [26]: test[:] > > Out[26]: > > array([[ 1., 3., 1., 2., 3., 2., 2., 3., 0., 0.], > > [ 0., 3., 0., 2., 3., 2., 2., 3., 1., 1.]], > > dtype=float32) > > > > > > As you can see, by using the extended slicing notation, it is very > > easy to overwrite the parts of the array that you are interested > > in. > > > > Hope this helps, > > > > -- > > Francesc Alted > > Freelance developer > > Tel +34-964-282-249 -- Francesc Alted Freelance developer Tel +34-964-282-249 ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Pytables-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pytables-users
