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

Function log

numpy/lib/scimath.py:252–296  ·  view source on GitHub ↗

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

(x)

Source from the content-addressed store, hash-verified

250
251@array_function_dispatch(_unary_dispatcher)
252def log(x):
253 """
254 Compute the natural logarithm of `x`.
255
256 Return the "principal value" (for a description of this, see `numpy.log`)
257 of :math:`log_e(x)`. For real `x > 0`, this is a real number (``log(0)``
258 returns ``-inf`` and ``log(np.inf)`` returns ``inf``). Otherwise, the
259 complex principle value is returned.
260
261 Parameters
262 ----------
263 x : array_like
264 The value(s) whose log is (are) required.
265
266 Returns
267 -------
268 out : ndarray or scalar
269 The log of the `x` value(s). If `x` was a scalar, so is `out`,
270 otherwise an array is returned.
271
272 See Also
273 --------
274 numpy.log
275
276 Notes
277 -----
278 For a log() that returns ``NAN`` when real `x < 0`, use `numpy.log`
279 (note, however, that otherwise `numpy.log` and this `log` are identical,
280 i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`, and,
281 notably, the complex principle value if ``x.imag != 0``).
282
283 Examples
284 --------
285 >>> np.emath.log(np.exp(1))
286 1.0
287
288 Negative arguments are handled "correctly" (recall that
289 ``exp(log(x)) == x`` does *not* hold for real ``x < 0``):
290
291 >>> np.emath.log(-np.exp(1)) == (1 + np.pi * 1j)
292 True
293
294 """
295 x = _fix_real_lt_zero(x)
296 return nx.log(x)
297
298
299@array_function_dispatch(_unary_dispatcher)

Callers 15

test_testUfuncs1Method · 0.90
legacy_gaussFunction · 0.50
legacy_standard_gammaFunction · 0.50
legacy_betaFunction · 0.50
legacy_vonmisesFunction · 0.50
legacy_logseriesFunction · 0.50
logfactorialFunction · 0.50
hypergeometric_hruaFunction · 0.50
random_standard_gammaFunction · 0.50

Calls 1

_fix_real_lt_zeroFunction · 0.85

Tested by 6

test_testUfuncs1Method · 0.72
test_basic_ufuncsMethod · 0.40
test_numpyarithmeticMethod · 0.40