NumPy Tutorial NumPy Statistics NumPy References

NumPy - log() function



The NumPy log() function is used to calculate the natural logarithm (base e) of a given value.

Syntax

numpy.log(x, out=None)

Parameters

x Required. Specify array (array_like) containing elements, of which the natural logarithm is calculated.
out Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

Return Value

Returns the natural logarithm of each element of x.

Example:

In the example below, numpy log() function is used to calculate the natural logarithm of each element present in array Arr.

import numpy as np

Arr = np.array([1, 2, 3, 4])

print("The natural logarithm of values:")
print(np.log(Arr))

The output of the above code will be:

The natural logarithm of values:
[ 0.          0.69314718  1.09861229  1.38629436]

❮ NumPy - Functions