[SciPy-User] Convert hdf5 file content to numpy array

Joon Ro joonpyro at gmail.com
Wed Jul 20 22:52:52 EDT 2011


On Wed, 20 Jul 2011 16:27:43 -0500, Thomas Königstein <thkoe002 at gmail.com>  
wrote:

> I just wonder why it doesn't work with pytables, and also why the
> f.get()-method that you proposed doesn't work for me... I get a "get()  
> takes
> 3 arguments, 2 given" error... any clues? I just installed h5py (version
> 1.2.1 on python 2 .6), the code I tried was
> 'f.get("/root/PE_Electrons_1")'.. anyways, thanks for the help, cheers
> Thomas
>

I'm not sure if you used pytables to create the hdf5 file, but if you did,  
it seems you used createTable method. In this case what you get is a  
structured array. (http://www.scipy.org/Cookbook/Recarray) And each record  
is numpy.void type.

If you want to store a numpy array without variable names, use createArray  
method instead of createTable.

Anyway, you can convert the structured array into ndarray with:

>>> array([ptcl[:][col] for col in test.dtype.names]).T

There might be better way to do this but I haven't found one.

-Joon



More information about the SciPy-User mailing list