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