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 data array partitions may be safely cast without loss of information. For example, if the partitions have data types ‘int64’ and ‘float32’ then the data array’s data type will be ‘float64’; or if the partitions have data types ‘int64’ and ‘int32’ then the data array’s data type will be ‘int64’.

Setting the data type to a numpy.dtype object, or any object convertible to a numpy.dtype object, will cause the data array elements to be recast to the specified type at the time that they are next accessed. This does not immediately change the 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 reinstates the default behaviour. Note that if the data type of any partitions have been 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 to dtype being set.

Examples

>>> print d.array
[0.5 1.5 2.5]
>>> d.dtype
dtype(float64')
>>> type(d.dtype)
<type 'numpy.dtype'>
>>> print d.array
[0.5 1.5 2.5]
>>> import numpy
>>> d.dtype = numpy.dtype(int)
>>> print d.array
[0 1 2]
>>> d.dtype = bool
>>> d.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.]

Previous topic

cf.Data.array

Next topic

cf.Data._FillValue

This Page