API · NumPy
Python Numpy.log() - Logarithm
Python numpy.log() function computes the natural logarithm of a numpy array. numpy.log2() and numpy.log10() calculate the logarithm with base 2 and 10.
Numpy.log() function calculates the natural logarithm of every element in the given array.
Syntax of numpy.log()
numpy.log(arr)
Parameters
arr |
input array |
Return
It returns an array of the natural logarithm of each element in the input array.
Example Codes: numpy.log()
import numpy as np
arr = [1, np.e, np.e**2, np.e**3]
print(np.log(arr))
Output:
[0. 1. 2. 3.]
Example Codes: numpy.log2() - Numpy Log Base 2
numpy.log2() is simliar to numpy.log(), but has the base as 2 instead of e.
import numpy as np
arr = [1, 2, np.e, 4]
print(np.log2(arr))
Output:
[0. 1. 1.44269504 2.]
Example Codes: numpy.log10() - Numpy Log Base 10
numpy.log10() is similar to numpy.log(), but has the base as 10 instead of e.
import numpy as np
arr = [1, np.e, 10, 100]
print(np.log10(arr))
Output:
[0. 0.43429448 1. 2.]