log(x, out=None, **kwargs)

Natural logarithm, element-wise. The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e.

  • x (ndarray) – Input value. Elements must be of real value.

  • out (ndarray or None, optional) – A location into which the result is stored. If provided, it must have the same shape and dtype as input ndarray. If not provided or None, a freshly-allocated array is returned.


  • y (ndarray) – The natural logarithm of x, element-wise. This is a scalar if x is a scalar.

  • .. note:: – Currently only supports data of real values and inf as input. Returns data of real value, inf, -inf and nan according to the input. This function differs from the original numpy.log in the following aspects:

    • Does not support complex number for now

    • Input type does not support Python native iterables(list, tuple, …).

    • out param: cannot perform auto broadcasting. out ndarray’s shape must be the same as the expected output.

    • out param: cannot perform auto type cast. out ndarray’s dtype must be the same as the expected output.

    • out param does not support scalar input case.


>>> a = np.array([1, np.exp(1), np.exp(2), 0], dtype=np.float64)
>>> np.log(a)
array([  0.,   1.,   2., -inf], dtype=float64)
>>> # Using the default float32 dtype leads to slightly different behavior
>>> a = np.array([1, np.exp(1), np.exp(2), 0])
>>> np.log(a)
array([  0.,  0.99999994,   2., -inf])
>>> np.log(1)