MCPcopy Create free account
hub / github.com/numpy/numpy / log2

Function log2

numpy/lib/scimath.py:390–434  ·  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

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

Callers

nothing calls this directly

Calls 1

_fix_real_lt_zeroFunction · 0.85

Tested by

no test coverage detected