colour.utilities.as_float¶
- colour.utilities.as_float(a, dtype=None)[source]¶
Converts given \(a\) variable to numeric using given type.
- Parameters
a (object) – Variable to convert.
dtype (object) – Type to use for conversion, default to the type defined by the
colour.constant.DEFAULT_INT_DTYPE
attribute. In the event where \(a\) cannot be converted, it is converted to ndarray using the type defined bycolour.constant.DEFAULT_FLOAT_DTYPE
attribute.
- Returns
\(a\) variable converted to numeric.
- Return type
ndarray
Warning
The behaviour of this definition is different than
colour.utilities.as_numeric()
definition when it comes to conversion failure: the former will forcibly convert \(a\) variable to ndarray using the type defined bycolour.constant.DEFAULT_FLOAT_DTYPE
attribute while the later will pass the \(a\) variable as is.Examples
>>> as_float(np.array([1])) 1.0 >>> as_float(np.arange(10)) array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])