Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Log at Base 10

Utilize the log10() function to compute the logarithm with base 10.

Example

Calculate the base 10 logarithm of all elements in the following array:

import numpy as np

arr = np.arange(110)

print(np.log10(arr))

Natural Log, or Log at Base e

Employ the log() function to calculate the logarithm with base e.

Example

Calculate the base e logarithm of all elements in the following array:

import numpy as np

arr = np.arange(110)

print(np.log(arr))

Log at Any Base

NumPy does not offer a built-in function for calculating logarithms with an arbitrary base. However, we can use the frompyfunc() function in conjunction with the built-in math.log() function, which accepts two input parameters and returns one output parameter.

Example

from math import log
import numpy as np

nplog = np.frompyfunc(log, 21)

print(nplog(10015))