# colour.algebra.sdiv#

colour.algebra.sdiv(a: FloatingOrArrayLike, b: FloatingOrArrayLike) FloatingOrNDArray[source]#

Divide given array $$b$$ with array $$b$$ while handling zero-division.

This definition avoids NaNs and +/- infs generation when array $$b$$ is equal to zero. This behaviour can be controlled with the colour.algebra.set_sdiv_mode() definition or with the sdiv_mode() context manager. The following modes are available:

• Numpy: The current Numpy zero-division handling occurs.

• Ignore: Zero-division occurs silently.

• Warning: Zero-division occurs with a warning.

• Ignore Zero Conversion: Zero-division occurs silently and NaNs or +/- infs values are converted to zeros. See numpy.nan_to_num() definition for more details.

• Warning Zero Conversion: Zero-division occurs with a warning and NaNs or +/- infs values are converted to zeros. See numpy.nan_to_num() definition for more details.

• Ignore Limit Conversion: Zero-division occurs silently and NaNs or +/- infs values are converted to zeros or the largest +/- finite floating point values representable by the division result numpy.dtype. See numpy.nan_to_num() definition for more details.

• Warning Limit Conversion: Zero-division occurs with a warning and NaNs or +/- infs values are converted to zeros or the largest +/- finite floating point values representable by the division result numpy.dtype.

Parameters:
• a (FloatingOrArrayLike) – Numerator array $$a$$.

• b (FloatingOrArrayLike) – Denominator array $$b$$.

Returns:

Array $$b$$ safely divided by $$a$$.

Return type:

np.floating or numpy.ndarray

Examples

>>> a = np.array([0, 1, 2])
>>> b = np.array([2, 1, 0])
>>> sdiv(a, b)
array([ 0.,  1.,  0.])
>>> try:
...     with sdiv_mode("Raise"):
...         sdiv(a, b)
... except Exception as error:
...     error
FloatingPointError('divide by zero encountered in...divide')
>>> with sdiv_mode("Ignore Zero Conversion"):
...     sdiv(a, b)
array([ 0.,  1.,  0.])
>>> with sdiv_mode("Warning Zero Conversion"):
...     sdiv(a, b)
array([ 0.,  1.,  0.])
>>> with sdiv_mode("Ignore Limit Conversion"):
...     sdiv(a, b)
array([  0.00000000e+000,   1.00000000e+000,   1.79769313e+308])
>>> with sdiv_mode("Warning Limit Conversion"):
...     sdiv(a, b)
array([  0.00000000e+000,   1.00000000e+000,   1.79769313e+308])