colour.utilities.as_float

colour.utilities.as_float(a: NumberOrArrayLike, dtype: Optional[Type[DTypeFloating]] = None) FloatingOrNDArray[source]

Attempt to convert given variable \(a\) to numpy.floating using given numpy.dtype. If variable \(a\) is not a scalar or 0-dimensional, it is converted to numpy.ndarray.

Parameters
  • a (NumberOrArrayLike) – Variable to convert.

  • dtype (Optional[Type[DTypeFloating]]) – numpy.dtype to use for conversion, default to the numpy.dtype defined by the colour.constant.DEFAULT_FLOAT_DTYPE attribute.

Returns

Variable \(a\) converted to numpy.floating.

Return type

numpy.floating or numpy.ndarray

Examples

>>> as_float(np.array([1]))
1.0
>>> as_float(np.arange(10))
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])