stuarteberg
unread,Feb 15, 2013, 1:59:40 PM2/15/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to h5...@googlegroups.com
Hi,
I'm wondering if there's a way to create h5py dataset views, much like numpy array views.
Ideally, I would like to use h5py datasets in place of numpy arrays, without needing to distinguish between the two. Is that possible?
This annotated transcript shows what I mean.
Thanks,
Stuart
# Make a zero-valued dataset
In [51]: f = h5py.File('example.h5', 'w')
In [52]: d = f.create_dataset('dset', data=numpy.zeros((4,4)))
# Make a zero-valued array for comparison
In [53]: a = numpy.zeros((4,4))
# This function modifies all entries of the provided array view
In [54]: def update_view(view):
....: view[:] = 1
....:
# Array is initially zero....
In [55]: a
Out[55]:
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
In [56]: update_view(a[0])
# ... and now it's been updated with some ones.
In [57]: a
Out[57]:
array([[ 1., 1., 1., 1.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
# dataset is initially zero....
In [58]: d[:]
Out[58]:
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
In [59]: update_view(d[0])
# .... but it isn't updated. (d[:] was a copy, not a view)
In [60]: d[:]
Out[60]:
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])