colour.utilities.as_ndarray#
- colour.utilities.as_ndarray(a: Any) np.ndarray[source]#
Convert the specified array \(a\) to a
numpy.ndarray.This function handles arrays from any backend (JAX, PyTorch, CuPy, etc.) by moving them to the host when direct conversion is not possible, e.g., for device-resident arrays.
- Parameters:
a (Any) – Array, scalar, or Python sequence to convert.
- Returns:
NumPy array.
- Return type:
Notes
Unlike
as_array()/as_float_array()siblings,as_ndarray()does not honour_NDARRAY_COPY_ENABLED. It is a backend-host hand-off boundary helper, not a copy toggle; the returned array shares storage with the input wherever the backend allows.
Examples
>>> import numpy as np >>> as_ndarray(np.array([1, 2, 3])) array([1, 2, 3])
Round-trip a PyTorch tensor on a non-host device:
>>> import torch >>> as_ndarray(torch.tensor([1, 2, 3], device="mps")) array([1, 2, 3])