cfdm.Data.compute¶
-
Data.
compute
(_force_to_memory=True)[source]¶ A view of the computed data.
In-place changes to the returned array might affect the underlying Dask array, depending on how the that Dask array has been defined.
The returned array has the same mask hardness and fill value as the data.
Compare with
array
.Performance
compute
causes all delayed operations to be computed.New in version (cfdm): 1.11.2.0
See also
- Parameters
- _force_to_memory:
bool
, optional If True (the default) then force the data resulting from computing the returned Dask graph to be in memory. If False then the data resulting from computing the Dask graph may or may not be in memory, depending on the nature of the stack
- _force_to_memory:
- Returns
An in-memory view of the data
Examples
>>> d = cfdm.Data([1, 2, 3.0], 'km') >>> d.compute() array([1., 2., 3.])
>>> from scipy.sparse import csr_array >>> d = cfdm.Data(csr_array((2, 3))) >>> d.compute() <2x3 sparse array of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format> >>> d.array array([[0., 0., 0.], [0., 0., 0.]]) >>> d.compute().toarray() array([[0., 0., 0.], [0., 0., 0.]])
>>> f = cfdm.example_field(0) >>> cfdm.write(f, 'file.nc') >>> f = cfdm.read('file.nc')[0] >>> print(f.data.compute()) [[0.007 0.034 0.003 0.014 0.018 0.037 0.024 0.029] [0.023 0.036 0.045 0.062 0.046 0.073 0.006 0.066] [0.11 0.131 0.124 0.146 0.087 0.103 0.057 0.011] [0.029 0.059 0.039 0.07 0.058 0.072 0.009 0.017] [0.006 0.036 0.019 0.035 0.018 0.037 0.034 0.013]] >>> f.data.compute(_force_to_memory=False) <NetCDF4Array(5, 8): file.nc, q(5, 8)>