Reading scalar datasets

2,708 views
Skip to first unread message

Filipe Maia

unread,
Jan 10, 2011, 9:08:19 PM1/10/11
to h5py
Hi,

This is a really silly question but I couldn't find the answer in the
documentation.
I am trying to read a scalar dataset but I don't know know.
For example lets imagine I create it like

file.create_dataset("distance",data=0.65) # in meters
file.create_dataset("name",data="string")

How do I read this back?

print str(file["name"]) and print file["name"] without much success.

Thanks for the help,
Filipe

Andrew Collette

unread,
Jan 11, 2011, 12:27:27 AM1/11/11
to h5...@googlegroups.com
Hi Filipe,

> This is a really silly question but I couldn't find the answer in the
> documentation.
> I am trying to read a scalar dataset but I don't know know.
>

> How do I read this back?

It looks a little funny but h5py uses the NumPy syntax:

dataset = file["name"]
data = dataset[()]

With older versions of h5py, dataset.value and dataset[...] will also
work, although these are discouraged.

Andrew

Reply all
Reply to author
Forward
0 new messages