Related Articles

Related Articles

Compute the natural logarithm of one plus each element in floating-point accuracy Using NumPy
  • Last Updated : 02 Sep, 2020

 Let’s see the program for computing the natural logarithm of one plus each element of a given array in floating-point accuracy using NumPy library.

For doing this task we are using numpy.log1p() function of NumPy. This function returns the array of natural logarithm of one plus each element of the input array.

Syntax: numpy.log1p(arr, out = None, *, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None, ufunc ‘log1p’)

Now, let’s see an example:

Example 1:



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import numpy library
import numpy as np
  
# Create a numpy array
arr = np.array([1e-90, 1e-100])
  
# Applying the function
rslt = np.log1p(arr)
  
print(rslt)

chevron_right


Output:

[1.e-090 1.e-100]

Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import numpy library
import numpy as np
  
# Create a numpy array
arr = np.array([1, 2, 3, 4])
  
# Applying the function
rslt = np.log1p(arr)
  
print(rslt)

chevron_right


Output:

[0.69314718 1.09861229 1.38629436 1.60943791]

Example 3:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import numpy library
import numpy as np
  
# Create a numpy array
arr = np.array([1, 1e-1, 3, 1e-0])
  
# Applying the function
rslt = np.log1p(arr)
  
print(rslt)

chevron_right


Output:

[0.69314718 0.09531018 1.38629436 0.69314718]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :