Numpy log10() is a mathematical function that is used to get the natural logarithm of any object or an array with the base 10.
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 arrayout
(optional) - the output array where the result will be storedwhere
(optional) - a boolean array indicating where to compute the logarithmcasting
(optional) - casting behavior when converting data typesdtype
(optional) - the data type of the returned outputlog10() Return Value
The numpy.log10()
method returns an array with the corresponding base-10 logarithmic values.
# 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]
# 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]
Thanks for reading !!!
#python #numpy