Python Numpy.log() - Logarithm
-
Syntax of
numpy.log()
-
Example Codes:
numpy.log()
-
Example Codes:
numpy.log2()
- Numpy Log Base 2 -
Example Codes:
numpy.log10()
- Numpy Log Base 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.]
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn Facebook