MCPcopy Index your code
hub / github.com/numpy/numpy / log2

Function log2

numpy/lib/_scimath_impl.py:387–432  ·  view source on GitHub ↗

Compute the logarithm base 2 of `x`. Return the "principal value" (for a description of this, see `numpy.log2`) of :math:`log_2(x)`. For real `x > 0`, this is a real number (``log2(0)`` returns ``-inf`` and ``log2(np.inf)`` returns ``inf``). Otherwise, the complex principle val

(x)

Source from the content-addressed store, hash-verified

385@set_module('numpy.lib.scimath')
386@array_function_dispatch(_unary_dispatcher)
387def log2(x):
388 """
389 Compute the logarithm base 2 of `x`.
390
391 Return the "principal value" (for a description of this, see
392 `numpy.log2`) of :math:`log_2(x)`. For real `x > 0`, this is
393 a real number (``log2(0)`` returns ``-inf`` and ``log2(np.inf)`` returns
394 ``inf``). Otherwise, the complex principle value is returned.
395
396 Parameters
397 ----------
398 x : array_like
399 The value(s) whose log base 2 is (are) required.
400
401 Returns
402 -------
403 out : ndarray or scalar
404 The log base 2 of the `x` value(s). If `x` was a scalar, so is `out`,
405 otherwise an array is returned.
406
407 See Also
408 --------
409 numpy.log2
410
411 Notes
412 -----
413 For a log2() that returns ``NAN`` when real `x < 0`, use `numpy.log2`
414 (note, however, that otherwise `numpy.log2` and this `log2` are
415 identical, i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`,
416 and, notably, the complex principle value if ``x.imag != 0``).
417
418 Examples
419 --------
420
421 We set the printing precision so the example can be auto-tested:
422
423 >>> np.set_printoptions(precision=4)
424
425 >>> np.emath.log2(8)
426 3.0
427 >>> np.emath.log2([-4, -8, 8])
428 array([2.+4.5324j, 3.+4.5324j, 3.+0.j ])
429
430 """
431 x = _fix_real_lt_zero(x)
432 return nx.log2(x)
433
434
435def _power_dispatcher(x, p):

Callers

nothing calls this directly

Calls 1

_fix_real_lt_zeroFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…