colour.utilities.tsplit#

colour.utilities.tsplit(a: ArrayLike, dtype: Type[DTypeBoolean] | Type[DTypeReal] | None = None) → NDArray[source]#

Split the specified stacked array \(a\) along the last axis (tail) to produce an array of arrays.

Used to split a stacked array produced by the colour.utilities.tstack() definition.

Parameters:
Returns:

Array of arrays.

Return type:

numpy.ndarray

Notes

  • On the NumPy path, the returned array is an independent, contiguous copy: the leading-axis sub-arrays do not alias the input \(a\) and can be safely written to in-place. This copy is deliberate and not an avoidable overhead, splitting with a numpy.moveaxis() view instead would alias \(a\) (breaking that guarantee), and the contiguity also keeps downstream operations such as matrix multiplications fast.

  • On the Array API path, the split is a zero-copy numpy.moveaxis() view whose contiguity and aliasing semantics are managed by the backend.

Examples

>>> a = np.array([0, 0, 0])
>>> tsplit(a)
array([0., 0., 0.])
>>> a = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]])
>>> tsplit(a)
array([[0., 1., 2., 3., 4., 5.],
       [0., 1., 2., 3., 4., 5.],
       [0., 1., 2., 3., 4., 5.]])
>>> a = np.array(
...     [
...         [
...             [0, 0, 0],
...             [1, 1, 1],
...             [2, 2, 2],
...             [3, 3, 3],
...             [4, 4, 4],
...             [5, 5, 5],
...         ]
...     ]
... )
>>> tsplit(a)
array([[[0., 1., 2., 3., 4., 5.]],

       [[0., 1., 2., 3., 4., 5.]],

       [[0., 1., 2., 3., 4., 5.]]])