From e2fdc6a853ff5a5eac1f6aac69ef30d53a0779e3 Mon Sep 17 00:00:00 2001 From: andersooi Date: Thu, 13 Jun 2024 23:16:49 +0800 Subject: [PATCH 1/3] feat: new term entry for numpy log10 --- .../math-methods/terms/log10/log10.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 content/numpy/concepts/math-methods/terms/log10/log10.md diff --git a/content/numpy/concepts/math-methods/terms/log10/log10.md b/content/numpy/concepts/math-methods/terms/log10/log10.md new file mode 100644 index 00000000000..af87b681650 --- /dev/null +++ b/content/numpy/concepts/math-methods/terms/log10/log10.md @@ -0,0 +1,61 @@ +--- +Title: '.log10()' +Description: 'Calculates the base 10 logarithm of each element in an array.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Arrays' + - 'Functions' + - 'NumPy' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +In NumPy, the **`.log10()`** method is used to calculate 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 + +```pseudo +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. + +## Example + +The below example demonstrates the use of the `.log10()` function: + +```py +import numpy as np + +result = np.log10([1e-15, -3., 10, 100]) + +print(result) +``` + +The output of the above code is shown below: + +```shell +[-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: + +```codebyte/python +import numpy as np + +result = np.log10([1, 0.1, 1000], where=np.array([1, 0.1, 1000]) > 0) + +print(result) +``` From c567393f24c5e2e64adc95fdf9f8c81025fd1f87 Mon Sep 17 00:00:00 2001 From: andersooi Date: Sat, 22 Jun 2024 18:09:03 +0800 Subject: [PATCH 2/3] fix: made changes based on comments --- content/numpy/concepts/math-methods/terms/log10/log10.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/numpy/concepts/math-methods/terms/log10/log10.md b/content/numpy/concepts/math-methods/terms/log10/log10.md index af87b681650..fc6922f1acd 100644 --- a/content/numpy/concepts/math-methods/terms/log10/log10.md +++ b/content/numpy/concepts/math-methods/terms/log10/log10.md @@ -13,7 +13,7 @@ CatalogContent: - 'paths/computer-science' --- -In NumPy, the **`.log10()`** method is used to calculate base 10 logarithm of each element in an array. It is primarily used in scientific computations and mathematical applications where logarithmic scaling is required. +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 From 6189780e3d35736a75a40ddf46ac8aa1ae8abef2 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 24 Jun 2024 14:37:52 +0530 Subject: [PATCH 3/3] Update log10.md minor changes --- .../concepts/math-methods/terms/log10/log10.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/content/numpy/concepts/math-methods/terms/log10/log10.md b/content/numpy/concepts/math-methods/terms/log10/log10.md index fc6922f1acd..dcd28c2af41 100644 --- a/content/numpy/concepts/math-methods/terms/log10/log10.md +++ b/content/numpy/concepts/math-methods/terms/log10/log10.md @@ -1,19 +1,19 @@ --- Title: '.log10()' -Description: 'Calculates the base 10 logarithm of each element in an array.' +Description: 'Calculates the base-10 logarithm of each element in an array.' Subjects: - 'Computer Science' - 'Data Science' Tags: - 'Arrays' - - 'Functions' + - 'Methods' - 'NumPy' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -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. +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 @@ -21,7 +21,7 @@ In NumPy, the **`.log10()`** method is used to calculate the base 10 logarithm o numpy.log10(array, out=None, where=True) ``` -- `array`: An array-like structure containing the elements for which the base 10 algorithm will be applied. +- `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. @@ -30,7 +30,7 @@ numpy.log10(array, out=None, where=True) ## Example -The below example demonstrates the use of the `.log10()` function: +The below example demonstrates the use of the `.log10()` method: ```py import numpy as np @@ -40,7 +40,7 @@ result = np.log10([1e-15, -3., 10, 100]) print(result) ``` -The output of the above code is shown below: +The code above will generate the following output: ```shell [-15. nan 1. 2.] @@ -50,7 +50,7 @@ The output of the above code is shown below: ## Codebyte Example -In this codebyte example, the `.log10()` method only computes the base 10 logarithm of positive elements in the array: +In this codebyte example, the `.log10()` method only computes the base-10 logarithm of positive elements in the array: ```codebyte/python import numpy as np