dask.array.Array.store

dask.array.Array.store

Array.store(targets: ArrayLike | Delayed | Collection[ArrayLike | Delayed], lock: bool | Lock = True, regions: tuple[slice, ...] | Collection[tuple[slice, ...]] | None = None, compute: bool = True, return_stored: bool = False, load_stored: bool | None = None, **kwargs)[source]

Store dask arrays in array-like objects, overwrite data in target

This stores dask arrays into object that supports numpy-style setitem indexing. It stores values chunk by chunk so that it does not have to fill up memory. For best performance you can align the block size of the storage target with the block size of your array.

If your data fits in memory then you may prefer calling np.array(myarray) instead.

Parameters
sources: Array or collection of Arrays
targets: array-like or Delayed or collection of array-likes and/or Delayeds

These should support setitem syntax target[10:20] = .... If sources is a single item, targets must be a single item; if sources is a collection of arrays, targets must be a matching collection.

lock: boolean or threading.Lock, optional

Whether or not to lock the data stores while storing. Pass True (lock each file individually), False (don’t lock) or a particular threading.Lock object to be shared among all writes.

regions: tuple of slices or collection of tuples of slices, optional

Each region tuple in regions should be such that target[region].shape = source.shape for the corresponding source and target in sources and targets, respectively. If this is a tuple, the contents will be assumed to be slices, so do not provide a tuple of tuples.

compute: boolean, optional

If true compute immediately; return dask.delayed.Delayed otherwise.

return_stored: boolean, optional

Optionally return the stored result (default False).

load_stored: boolean, optional

Optionally return the stored result, loaded in to memory (default None). If None, load_stored is True if return_stored is True and compute is False. This is an advanced option. When False, store will return the appropriate target for each chunk that is stored. Directly computing this result is not what you want. Instead, you can use the returned target to execute followup operations to the store.

kwargs:

Parameters passed to compute/persist (only used if compute=True)

Returns
If return_stored=True

tuple of Arrays

If return_stored=False and compute=True

None

If return_stored=False and compute=False

Delayed

Examples

>>> import h5py  
>>> f = h5py.File('myfile.hdf5', mode='a')  
>>> dset = f.create_dataset('/data', shape=x.shape,
...                                  chunks=x.chunks,
...                                  dtype='f8')  
>>> store(x, dset)  

Alternatively store many arrays at the same time

>>> store([x, y, z], [dset1, dset2, dset3])