Numpy.log10() Method Example | How to Use Numpy.log10() Method Function in Python

Numpy log10() is a mathematical function that is used to get the natural logarithm of any object or an array with the base 10.

Syntax

numpy.log10(x, out = None, where = True, casting = 'same_kind', dtype = None)

log10() Arguments

The numpy.log10() method takes the following arguments:

  • x - an input array
  • out (optional) - the output array where the result will be stored
  • where (optional) - a boolean array indicating where to compute the logarithm
  • casting (optional) - casting behavior when converting data types
  • dtype (optional) - the data type of the returned output

log10() Return Value

The numpy.log10() method returns an array with the corresponding base-10 logarithmic values.

Example 1: How to Use np.log10() Method

# Importing numpy
import numpy as np

# We will create an 1D array
arr = np.array([4, 14, 10, 63, 11, 4, 64])
# Printing the array
print("The array is: ", arr)
# Shape of the array
print("Shape of the array is : ", np.shape(arr))

# Calculating natural log of value arr[i]+1
out = np.log10(arr)
print("Natural logarithm of the given array of base 10 is ")
print(out)

Output

The array is: [ 4 14 10 63 11 4 64]

Shape of the array is : (7,)

Natural logarithm of the given array of base 10 is
[0.60205999 1.14612804 1. 1.79934055 1.04139269 0.60205999
 1.80617997]

Example 2: Plotting the np.log10() Method

# Importing numpy
import numpy as np
import matplotlib.pyplot as plt

# We will create an 1D array
arr = np.array([40, 2.4, 0.14, 63, 1.2, 1, 4])
# Printing the array
print("The array is: ", arr)
# Shape of the array
print("Shape of the array is : ", np.shape(arr))

# Calculating natural log of value arr[i]+1
out = np.log10(arr)
print("Natural logarithm of the given array of base 10 is ")
print(out)

plt.plot(arr, arr, color='green', marker='x')

# Ploting of natural log array in Graph
# Color will be in blue
plt.plot(out, arr, color='blue', marker='o')

# Showing the Graphical represntation
plt.title("numpy.log10()")
plt.xlabel("Natural Log Array")
plt.ylabel("Original Array")
plt.show()

Output

The array is: [40. 2.4 0.14 63. 1.2 1. 4. ]

Shape of the array is : (7,)

Natural logarithm of the given array of base 10 is
[ 1.60205999 0.38021124 -0.85387196 1.79934055 0.07918125 0.
 0.60205999]
np log10() Function in Python

Thanks for reading !!!

#python #numpy

Numpy.log10() Method Example | How to Use Numpy.log10() Method Function in Python
36.45 GEEK