colour.utilities.ndarray_write#

colour.utilities.ndarray_write(a: ArrayLike) Generator[source]#

Define a context manager that temporarily sets the specified array \(a\) to writeable for operations, then restores it to read-only.

Parameters:

a (ArrayLike) – Array \(a\) to operate on.

Yields:

Generator – Array \(a\) made temporarily writeable.

Return type:

Generator

Examples

>>> a = np.linspace(0, 1, 10)
>>> a.setflags(write=False)
>>> try:
...     a += 1
... except ValueError:
...     pass
>>> with ndarray_write(a):
...     a += 1