dpnp.log2

dpnp.log2(x, out=None, where=True, order='K', dtype=None, subok=True, **kwargs)

Computes the base-2 logarithm for each element \(x_i\) of input array x.

For full documentation refer to numpy.log2.

Parameters:
  • x ({dpnp.ndarray, usm_ndarray}) -- Input array, expected to have a floating-point data type.

  • 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 ({None, "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 base-2 logarithm of x. 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 argument kwargs is currently unsupported. Otherwise NotImplementedError exception will be raised.

See also

dpnp.log

Calculate \(\log(x)\), element-wise.

dpnp.log10

Calculate \(\log_{10}(x)\), element-wise.

dpnp.log1p

Calculate \(\log(1 + x)\), element-wise.

Notes

dpnp.log2 is a multivalued function: for each x there are infinitely many numbers z such that \(2^z = x\). The convention is to return the z whose the imaginary part lies in the interval \([-\pi, \pi]\).

For real-valued floating-point input data types, dpnp.log2 always returns real output. For each value that cannot be expressed as a real number or nfinity, it yields NaN.

For complex floating-point input data types, dpnp.log2 is a complex analytic function that has, by convention, the branch cuts \((-\infty, 0)\) and is continuous from above on it.

In the cases where the input has a negative real part and a very small negative complex part (approaching 0), the result is so close to \(-\pi\) that it evaluates to exactly \(-\pi\).

Examples

>>> import dpnp as np
>>> x = np.array([0, 1, 2, 2**4])
>>> np.log2(x)
array([-inf, 0.0, 1.0, 4.0])
>>> xi = np.array([0+1.j, 1, 2+0.j, 4.j])
>>> np.log2(xi)
array([ 0.+2.26618007j,  0.+0.j        ,  1.+0.j        ,  2.+2.26618007j])