.log10()
Published Jun 24, 2024
Contribute to Docs
In NumPy, the .log10()
method is used to calculate the base-10 logarithm of each element in an array. It is primarily used in scientific computations and mathematical applications where logarithmic scaling is required.
Syntax
numpy.log10(array, out=None, where=True)
array
: An array-like structure containing the elements for which the base-10 algorithm will be applied.out
(Optional): The array where the result is to be stored. If not provided, a new array is created to store the results.where
(Optional): The condition (array of boolean values) that determines which elements will the method be applied on.- If the condition is
True
for a particular element, the logarithm is computed for that element. - If the condition is
False
for a particular element, the logarithm is not computed for that element and the original element is retained. - If not provided, the logarithm is computed for all elements.
- If the condition is
Example
The below example demonstrates the use of the .log10()
method:
import numpy as npresult = np.log10([1e-15, -3., 10, 100])print(result)
The code above will generate the following output:
[-15. nan 1. 2.]
Note: Running the above code will result in a
RuntimeWarning
due to attempting to calculate the logarithm of a negative number, which is not a valid operation.
Codebyte Example
In this codebyte example, the .log10()
method only computes the base-10 logarithm of positive elements in the array:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours