colour.utilities.as_array#

colour.utilities.as_array(a: ArrayLike | KeysView | ValuesView, dtype: Type[DType] | None = None) NDArray[source]#

Convert the specified variable \(a\) to an 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 a numpy.ndarray.

Parameters:
  • a (ArrayLike | KeysView | ValuesView) – Variable \(a\) to convert.

  • dtype (Type[DType] | None) – numpy.dtype to use for conversion, default to the numpy.dtype defined by the colour.constant.DTYPE_FLOAT_DEFAULT attribute.

Returns:

Variable \(a\) converted to an array in the input’s namespace.

Return type:

numpy.ndarray or backend tensor

Examples

>>> as_array([1, 2, 3])
array([1, 2, 3]...)
>>> as_array([1, 2, 3], dtype=DTYPE_FLOAT_DEFAULT)
array([1., 2., 3.])