Python Numpy.log() - Logarithm

  1. Syntax of numpy.log()
  2. Example Codes: numpy.log()
  3. Example Codes: numpy.log2() - Numpy Log Base 2
  4. Example Codes: numpy.log10() - Numpy Log Base 10

Numpy.log() function calculates the natural logarithm of every element in the given array.

numpy natural logarithm

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.

numpy log2

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.

numpy log10

import numpy as np

arr = [1, np.e, 10, 100]
print(np.log10(arr))

Output:

[0. 0.43429448 1. 2.]
comments powered by Disqus