cf.Data.dtype¶

Data.
dtype
¶ The
numpy
datatype of the data array.By default this is the datatype with the smallest size and smallest scalar kind to which all subarrays of the master data array may be safely cast without loss of information. For example, if the subarrays have datatypes ‘int64’ and ‘float32’ then the master data array’s datatype will be ‘float64’; or if the subarrays have datatypes ‘int64’ and ‘int32’ then the master data array’s datatype will be ‘int64’.
Setting the datatype to a
numpy.dtype
object, or any object convertible to anumpy.dtype
object, will cause the master data array elements to be recast to the specified type at the time that they are next accessed, and not before. This does not immediately change the master data array elements, so, for example, reinstating the original datatype prior to data access results in no loss of information.Deleting the datatype forces the default behaviour. Note that if the datatype of any subarrays has changed after
dtype
has been set (which could occur if the data array is accessed) then the reinstated default datatype may be different to the datatype prior todtype
being set.Examples:
>>> d = cf.Data([0.5, 1.5, 2.5]) >>> d.dtype dtype(float64') >>> type(d.dtype) <type 'numpy.dtype'>
>>> d = cf.Data([0.5, 1.5, 2.5]) >>> import numpy >>> d.dtype = numpy.dtype(int) >>> print(d.array) [0 1 2] >>> d.dtype = bool >>> print(d.array) [False True True] >>> d.dtype = 'float64' >>> print(d.array) [ 0. 1. 1.]
>>> d = cf.Data([0.5, 1.5, 2.5]) >>> d.dtype = int >>> d.dtype = bool >>> d.dtype = float >>> print(d.array) [ 0.5 1.5 2.5]