# colour.algebra.common Module¶

## Algebra Common Utilities¶

Defines algebra common utilities objects that don”t belong to any algebra specific category.

colour.algebra.common.INTEGER_THRESHOLD = 0.001

Integer threshold value.

INTEGER_THRESHOLD : numeric

colour.algebra.common.steps(distribution)[source]

Returns the steps of given distribution.

Parameters: distribution (array_like) – Distribution to retrieve the steps. Distribution steps. tuple

Examples

Uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 5])
>>> steps(y)
(1,)


Non-uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 8])
>>> steps(y)
(1, 4)

colour.algebra.common.closest(y, x)[source]

Returns closest $$y$$ variable element to reference $$x$$ variable.

Parameters: y (array_like) – Variable to search for the closest element. x (numeric) – Reference variable. Closest $$y$$ variable element. numeric

Examples

>>> y = np.array([24.31357115, 63.62396289, 55.71528816, 62.70988028, 46.84480573, 25.40026416])
>>> closest(y, 63)
62.70988028

colour.algebra.common.to_ndarray(x, data_type=<type 'numpy.float64'>)[source]

Converts given $$x$$ variable to ndarray.

Parameters: x (object) – Variable to convert. data_type (dtype) – ndarray data type. $$x$$ variable converted to ndarray. ndarray

Examples

>>> to_ndarray(1)
array([ 1.])

colour.algebra.common.is_uniform(distribution)[source]

Returns if given distribution is uniform.

Parameters: distribution (array_like) – Distribution to check for uniformity. Is distribution uniform. bool

Examples

Uniformly spaced variable:

>>> y = np.array([1, 2, 3, 4, 5])
>>> is_uniform(y)
True


Non-uniformly spaced variable:

>>> y = np.array([1, 2, 3.1415, 4, 5])
>>> is_uniform(y)
False

colour.algebra.common.is_iterable(x)[source]

Returns if given $$x$$ variable is iterable.

Parameters: x (object) – Variable to check the iterability. $$x$$ variable iterability. bool

Examples

>>> is_iterable([1, 2, 3])
True
>>> is_iterable(1)
False

colour.algebra.common.is_numeric(x)[source]

Returns if given $$x$$ variable is a number.

Parameters: x (object) – Variable to check. Is $$x$$ variable a number. bool

is_integer()

Examples

>>> is_numeric(1)
True
>>> is_numeric((1,))
False

colour.algebra.common.is_integer(x)[source]

Returns if given $$x$$ variable is an integer under given threshold.

Parameters: x (object) – Variable to check. Is $$x$$ variable an integer. bool

Notes

is_numeric()

Examples

>>> is_integer(1)
True
>>> is_integer(1.01)
False

colour.algebra.common.normalise(x, factor=1, clip=True)[source]

Normalises given array_like $$x$$ variable values and optionally clip them between.

Parameters: x (array_like) – $$x$$ variable to normalise. factor (numeric, optional) – Normalization factor clip (bool, optional) – Clip values between in domain [0, ‘factor’]. Normalised $$x$$ variable. ndarray

Examples

>>> x = np.array([0.48224885, 0.31651974, 0.22070513])
>>> normalise(x)
array([ 1.        ,  0.6563411...,  0.4576581...])