A Wednesday 21 May 2008, Glenn escrigué:
> Hello,
> I am using an EArray constructed as follows:
> fh.createEArray(grp,'normI',Float32Atom(),(0,512))
>
> When I try to append to it a numpy array with dimensions (512,), I
> get a rank mismatch error unless I first wrap the array as follows:
> np.array(np.zeros((512,0)),ndmin=2)
> Is there anyway around having to add this extra annoying code
> everywhere?
This is so mainly to allow in the future the possibility to have several
enlargeable dimensions in EArrays.
> Why shouldn't any array with 512 elements in one
> dimension and any set of singleton or non existent other dimensions
> be appendable?
There are many ways to do that. The most simple one is surrounding your
array by the necessary additional brackets, but this forces an
in-memory copy of your data array. A non-copy method is by using the
numpy.newaxis object. Here it is an example:
In [71]: f = tables.openFile("/tmp/test.h5", "w")
In [72]: normI = f.createEArray(f.root, "normI", tables.Float32Atom(),
(0,512))
In [73]: a = numpy.zeros((512,))
In [74]: normI.append([a]) # add necessary []'s
In [75]: normI.append(a[numpy.newaxis,:]) # using newaxis (no data
copy)
In [76]: normI
Out[76]:
/normI (EArray(2L, 512)) ''
atom := Float32Atom(shape=(), dflt=0.0)
maindim := 0
flavor := 'numpy'
byteorder := 'little'
chunkshape := (4, 512)
Cheers,
--
Francesc Altet
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