NumPy - log1p() function
The NumPy log1p() function is used to calculate the natural logarithm of (1 + number), i.e., log(1+number).
Syntax
numpy.log1p(a, out=None)
Parameters
a |
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 1 + each element of a.
Example:
In the example below, numpy log1p() function is used to calculate the natural logarithm of 1 + each element present in array Arr.
import numpy as np Arr = np.array([0, 1, 2, 3]) print("The natural logarithm of 1 + values:") print(np.log1p(Arr))
The output of the above code will be:
The natural logarithm of 1 + values: [ 0. 0.69314718 1.09861229 1.38629436]
❮ NumPy - Functions