How numpy log10 function works with examples

Posted on Apr 07, 2022

Learn how to use the numpy log10 function in Python

The numpy log10() function is used to calculate the base 10 logarithm of the input value.

The numpy.log10() function accepts either a number or an array of numbers.

The syntax of the function is as follows:


# or
numpy.log10([n, n, n, ...])

Here are some examples of the log10() function in action:

import numpy as np

# 1.255272505103306
np.log10([8, 29])
# array([ 2.07944154, 3.36729583 ])
# 2.4082399653118496

You can also create a graphical representation to compare the original array and the log10() array.

Here’s how to create a plot using the matplotlib library:

import numpy as np
import matplotlib.pyplot as plt
my_array = [2, 4, 6, 8, 10]
log10_array = np.log10(my_array)
plt.plot(my_array, my_array, color = 'green', marker = "*")
plt.plot(log10_array, my_array, color = 'red', marker = "o")

plt.title("Log10 array plot")

The output will be as follows:

Now you’ve learned how the numpy.log10() function works. Good work! 👍

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.