cf.Field.dtype

Field.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. For example, if the partitions have data types ‘int64’ and ‘float32’ then the data array’s data type will be ‘float64’.

Setting the data type to a numpy.dtype object, or any object convertible to a numpy.dtype object, will change the interpretation of the underlying data array elements. Note that the underlying data are not altered, so reinstating the original data type results in no loss of information.

Deleting the data type after setting it will reinstate the default behaviour. Deleting the data type when the default behaviour is in place will have no effect.

Examples

>>> f.dtype
dtype('float64')
>>> type(f.dtype)
<type 'numpy.dtype'>
>>> print f.array
[0.5 1.5 2.5]
>>> print f.array
[0.5 1.5 2.5]
>>> import numpy
>>> f.dtype = numpy.dtype(int)
>>> print f.array
[0 1 2]
>>> f.dtype = bool
>>> print f.array
[False  True  True]
>>> f.dtype = 'float64'
>>> print f.array
[0.5 1.5 2.5]

Previous topic

cf.Field.Data

Next topic

cf.Field._FillValue

This Page