colour.utilities.xp_reshape#
- colour.utilities.xp_reshape(a: ArrayLike, shape: Any, *, xp: ProtocolArrayNamespace | ModuleType | None = None) NDArray[source]#
Array API compatible implementation of
numpy.reshape().This typed wrapper exists because
xpis typed asAny, soxp.reshape(...)returnsAny. When the result is assigned back to a variable that was originally a function parameter (e.g.,a: ArrayLike), Pyright reverts the variable to its declared type instead of narrowing it. This wrapper declares-> NDArrayso that Pyright can track the narrowed type through reassignments.Callers must promote Python scalars / lists to the backend namespace beforehand (e.g. via
xp_as_float_array()), since strict backends like PyTorch reject raw scalars and the wrapper cannot infer the target device for a scalar input.- Parameters:
a (ArrayLike) – Input array.
shape (Any) – New shape.
xp (ProtocolArrayNamespace | ModuleType | None) – Array namespace module. If None, derived from
a.
- Returns:
Reshaped array.
- Return type: