A Monday 31 December 2007, Darren Dale escrigué: > Hello, > > I am writing a data acquisition client which receives a single index > with each new data point. I need to use that index to update some > multidimensional arrays. Is it possible to do this with pytables, > without loading each array into memory? I was hoping I could do > something like: > > t.root.entry.myarray.flat[i] = val > > but CArrays do not have a flat iterator. Is there a better solution > than this?: > > a = t.root.entry.myarray[:] > a.flat[i] = val > t.root.entry.myarray[:] = a > > I am surprised that even works, since myarray is a CArray and > myarray[:] is an ndarray. I didn't expect the file to be updated, but > it was. Could someone explain why?
Well, myarray[:] is not exactly an ndarray: its behaviour really depends on the context. When it is on the right side of an assignation, this is really a call to myarray.__getitem__(:) that *returns* an ndarray. But when at it is at the left, it calls myarray.__setitem__(:, a), so this is why this works. > I could also calculate the multidimensional index based on the shape > of myarray, but it would be really convenient if CArray provided a > flat view of the data. Well, this should be the 'correct' way to update the CArray. Feel free to open a ticket (http://www.pytables.org/trac/) for implementing the flat iterator and we will see what we can do. Cheers, -- >0,0< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data "-" ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users