2011/3/23 Adriano Vilela Barbosa <adriano.vil...@yahoo.com>
> Hello,
>
> I'm having a problem with PyTables that's driving me nuts. I'm probably
> doing
> something wrong, but I wonder if it could be a bug.
>
> Basically, I need to write a series of numpy arrays to an HDF file. Because
> of
> performance and compression requirements, I decided to convert each numpy
> array
> to a binary string and then write the resulting string to a CArray in the
> output
> HDF file. This works fine, as long as there are no trailing \x00 elements
> in the
> string. For some reason, trailing \x00 elements are NOT copied to the
> Carray.
>
[clip]
This is not a bug, but rather a feature of NumPy. Look at this:
>>> import numpy as np
>>> a = np.array(['aa\x00\x00'])
>>> a[0]
'aa' # hey! were have my trailing 0's gone?
>>> a.data[:]
'aa\x00\x00' # yeah, they still are in the data area of the array
I'd recommend you using the byte ('i1') type for achieving what you want:
>>> a.view('i1')
array([97, 97, 0, 0], dtype=int8)
Hope this helps,
--
Francesc Alted
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users