A Monday 02 June 2008, Jianfu Pan escrigué:
> I used createArray() to create a pytables array with data set.  I
> then added a bunch of attributes on the array node.  Now suppose I
> need to modify the data of the array (replacing the whole array so I
> don't care about elements access), what's the best way to do that?  I
> used pyhdf for HDF4 and there's a set() method, and I thought it's
> very convenient.  Is there something similar in pytables?  Thanks.

Yes, it is.  Use the __setitem__() method.  From the docstrings:

"""
Definition:       arr.__setitem__(self, key, value)
Docstring:
    Set a row, a range of rows or a slice in the array.

    It takes different actions depending on the type of the `key`
    parameter: if it is an integer, the corresponding array row is
    set to `value` (the value is broadcast when needed).  If the
    `key` is a slice, the row slice determined by it is set to
    `value` (as usual, if the slice to be updated exceeds the
    actual shape of the array, only the values in the existing
    range are updated).

    If the `value` is a multidimensional object, then its shape
    must be compatible with the shape determined by the `key`,
    otherwise, a ``ValueError`` will be raised.

    Example of use::

        a1[0] = 333        # assign an integer to a Integer Array row
        a2[0] = 'b'        # assign a string to a string Array row
        a3[1:4] = 5        # broadcast 5 to slice 1:4
        a4[1:4:2] = 'xXx'  # broadcast 'xXx' to slice 1:4:2
        # General slice update (a5.shape = (4,3,2,8,5,10).
        a5[1, ..., ::2, 1:4, 4:] = arange(1728, shape=(4,3,2,4,3,6))

"""

PS:  For PyTables only related questions, please use just the PyTables 
user list so as not to bother other HDF5 users not using it.

-- 
Francesc Alted
Freelance developer
Tel +34-964-282-249

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to