dpnp.logaddexp2

dpnp.logaddexp2(x1, x2, out=None, where=True, order='K', dtype=None, subok=True, **kwargs)

Calculates the logarithm of the sum of exponents in base-2 for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.

This function calculates log2(2**x1 + 2**x2). It is useful in machine learning when the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the base-2 logarithm of the calculated probability can be used instead. This function allows adding probabilities stored in such a fashion.

For full documentation refer to numpy.logaddexp2.

Parameters:
  • x1 ({dpnp.ndarray, usm_ndarray, scalar}) -- First input array, expected to have a real-valued floating-point data type. Both inputs x1 and x2 can not be scalars at the same time.

  • x2 ({dpnp.ndarray, usm_ndarray, scalar}) -- Second input array, also expected to have a real-valued floating-point data type. Both inputs x1 and x2 can not be scalars at the same time. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).

  • out ({None, dpnp.ndarray, usm_ndarray}, optional) -- Output array to populate. Array must have the correct shape and the expected data type. Default: None.

  • order ({"C", "F", "A", "K"}, optional) -- Memory layout of the newly output array, if parameter out is None. Default: "K".

Returns:

out -- An array containing the element-wise results. The data type of the returned array is determined by the Type Promotion Rules.

Return type:

dpnp.ndarray

Limitations

Parameters where and subok are supported with their default values. Keyword arguments kwargs are currently unsupported. Otherwise NotImplementedError exception will be raised.

See also

dpnp.logaddexp

Natural logarithm of the sum of exponentiation of inputs, element-wise.

dpnp.logsumexp

Logarithm of the sum of exponentiation of the inputs.

Examples

>>> import dpnp as np
>>> prob1 = np.log2(np.array(1e-50))
>>> prob2 = np.log2(np.array(2.5e-50))
>>> prob12 = np.logaddexp2(prob1, prob2)
>>> prob1, prob2, prob12
(array(-166.09640474), array(-164.77447665), array(-164.28904982))
>>> 2**prob12
array(3.5e-50)