NumPy log10() Function:
Numpy log10: The base-10 logarithm of all the elements of the given array is calculated using the log10() function of the NumPy module.
Syntax:
numpy.log10(a, out=None)
Parameters
a: This is required. It is the array or an object given as input.
out: This is optional. It is the location where the result will be stored. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.
Return Value:
Numpy log10: The base-10 logarithm of each element of a is returned by the log10() function of the NumPy module.
- Python numpy.log() Function with Examples
- Python NumPy floor() Function
- Python NumPy broadcast() Function
NumPy log10() Function in Python
Example1
Approach:
- Import numpy module using the import keyword
- Pass some random list as an argument to the array() function of the numpy module to create an array.
- Store it in a variable.
- Print the above-given array.
- Pass the above-given array as an argument to the log10() function of the numpy module to get the base-10 logarithmic values of each element of the given array.
- Store it in another variable.
- Print the base-10 logarithmic values of each element of the given array
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword
import numpy as np
# Pass some random list as an argument to the array() function
# of the Numpy module to create an array.
# Store it in a variable.
gvn_arry = np.array([5, 1, 2.4, 10.5, 4])
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the log10() function of the
# numpy module to get the base-10 logarithmic values of each element of
# the given array
# Store it in another variable.
rslt = np.log10(gvn_arry)
# Print the base-10 logarithmic values of each element of the given array
print("The base-10 logarithmic values of each element of the given array:")
print(rslt)
Output:
The above given array is: [ 5. 1. 2.4 10.5 4. ] The base-10 logarithmic values of each element of the given array: [0.69897 0. 0.38021124 1.0211893 0.60205999]
Example2(Plotting a Graph)
Approach:
- Import numpy module using the import keyword
- Import pyplot from the matplotlib module using the import keyword
- Give some random list as static input and store it in a variable.
- Pass the above-given array as an argument to the log10() function of the numpy module to get the base-10 logarithmic values of each element of the given array.
- Store it in another variable.
- Store the above input array in another variable for plotting the input array vs input array.
- Plot the input array versus input array with some random color and marker values using the plot() function of the matplotlib module.
- Plot the output array versus input array with some other random color and marker values using the plot function of the matplotlib module
- Give the title of the plot using the title() function of the matplotlib module
- Display the plot using the show() function of the matplotlib module.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword
import numpy as np
# Import pyplot from the matplotlib module using the import keyword
import matplotlib.pyplot as plt
# Give some random list as static input and store it in a variable.
gvn_arry = [2.1, 1, 2.8, 3.2, 4.3]
# Pass the above given array as an argument to the log10() function of the
# numpy module to get the base-10 logarithmic values of each element of
# the given array
# Store it in another variable.
rslt_arry = np.log10(gvn_arry)
# Store the above input array in another variable for plotting the input array vs input array.
temp_inputarry = [2.1, 1, 2.8, 3.2, 4.3]
# Plot the input array versus input array with some random color and marker values using
# the plot() function of the matplotlib module
plt.plot(gvn_arry, temp_inputarry, color = 'green', marker = "*")
# Plot the output array versus input array with some other random color
# and marker values using the plot function of the matplotlib module
plt.plot(rslt_arry, temp_inputarry, color = 'orange', marker = "o")
# Give the title of the plot using the title() function of the matplotlib module
plt.title("Plotting base-10 logarithmic values:")
plt.xlabel("X")
plt.ylabel("Y")
# Display the plot using the show() function of the matplotlib module.
plt.show()
Output: