MRocklin
MRocklin

Reputation: 57281

Simultaneously indexing fields and a slice using `h5py`

Given an H5Py file of the following type

In [41]: d.shape
Out[41]: (37450461,)

In [42]: d.dtype 
Out[42]: dtype([('transaction', '<i8'), ('sender', '<i8'), ('recipient', '<i8'),
                ('timestamp', '<i8'), ('value', '<f8')])

I would like to get out a few fields over just a few entries. I'm looking for something like the following:

In [43]: d[['timestamp', 'value'], :5]

Sadly this raises an error. I can break the query up into multiple parts and it works:

In [46]: d[:5][['timestamp', 'value']]

But this is inefficient.

Question

Is there any way to efficiently select a few fields and a few entries from a structured array stored in HDF5 using h5py?

Upvotes: 1

Views: 61

Answers (1)

MRocklin
MRocklin

Reputation: 57281

So I figured out my answer as I was writing the question

>>> d['timestamp', 'value', :5]

Upvotes: 2

Related Questions