log2

log2(x: array, /) array

Calculates an implementation-dependent approximation to the base 2 logarithm for each element x_i of the input array x.

Note

For complex floating-point operands, log2(conj(x)) must equal conj(log2(x)).

Parameters:

x (array) – input array. Should have a floating-point data type.

Returns:

out (array) – an array containing the evaluated base 2 logarithm for each element in x. The returned array must have a floating-point data type determined by Type Promotion Rules.

Notes

Special cases

For real-valued floating-point operands,

  • If x_i is NaN, the result is NaN.

  • If x_i is less than 0, the result is NaN.

  • If x_i is either +0 or -0, the result is -infinity.

  • If x_i is 1, the result is +0.

  • If x_i is +infinity, the result is +infinity.

For complex floating-point operands, special cases must be handled as if the operation is implemented using the standard change of base formula

\[\log_{2} x = \frac{\log_{e} x}{\log_{e} 2}\]

where \(\log_{e}\) is the natural logarithm, as implemented by log().

Changed in version 2022.12: Added complex data type support.