Utilize the log10() function to compute the logarithm with base 10.
Calculate the base 10 logarithm of all elements in the following array:
import numpy as np arr = np.arange(1, 10) print(np.log10(arr)) |
Employ the log() function to calculate the logarithm with base e.
Calculate the base e logarithm of all elements in the following array:
import numpy as np arr = np.arange(1, 10) print(np.log(arr)) |
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.
from math import log import numpy as np nplog = np.frompyfunc(log, 2, 1) print(nplog(100, 15)) |