colour.utilities.as_float_array#
- colour.utilities.as_float_array(a: ArrayLike, dtype: Type[DTypeFloat] | None = None) NDArrayFloat[source]#
Convert the specified variable \(a\) to a floating-point array using the specified
numpy.dtype.This is a namespace-aware boundary helper. When Array API dispatch is enabled and \(a\) is a non-NumPy array (e.g. JAX, PyTorch), the result is returned in \(a\)’s native namespace, on its device, and cast to
dtype. Otherwise the result is anumpy.ndarray. This is the convention used at function boundaries:a = as_float_array(a)followed byxp = array_namespace(a)recovers the caller’s backend.- Parameters:
a (ArrayLike) – Variable \(a\) to convert.
dtype (Type[DTypeFloat] | None) – Floating-point
numpy.dtypeto use for conversion, default to thenumpy.dtypedefined by thecolour.constant.DTYPE_FLOAT_DEFAULTattribute.
- Returns:
Variable \(a\) converted to a floating-point array in the input’s namespace.
- Return type:
numpy.ndarrayor backend tensor
Examples
>>> as_float_array([1, 2, 3]) array([1., 2., 3.])