cf.Data.dtype¶

Data.
dtype
¶ The
numpy
data type of the data array.By default this is the data type 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 data types ‘int64’ and ‘float32’ then the master data array’s data type will be ‘float64’; or if the subarrays have data types ‘int64’ and ‘int32’ then the master data array’s data type will be ‘int64’.
Setting the data type 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 data type prior to data access results in no loss of information.Deleting the data type forces the default behaviour. Note that if the data type of any subarrays has changed after
dtype
has been set (which could occur if the data array is accessed) then the reinstated default data type may be different to the data type 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]