def fill_array(self, target, value, chunk_size = 1000):
"""Fill the target HDF5 array with a single value. Useful for
initializing an array, since the rhdf5 package tends to segfault if you
load an uninitialized data set.
Parameters
----------
target: str
the location of the HDF5 array, e.g., "samples/time"
value: any
the value to fill the array with
chunk_size: int
the number of items to insert at a time. This only needs to be
increased for very large data sets.
"""
n = self.h5_table[target].shape[0]
chunks = np.append(np.arange(0, n, chunk_size), n)
for i in range(len(chunks)-1):
self.h5_table[target][chunks[i]:chunks[i+1]] = (
[value]*(chunks[i+1] - chunks[i]) )
评论列表
文章目录