Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Learn NumPy Logs

In NumPy, logarithm functions are included in the category of universal functions (ufuncs) and are used to compute the logarithm of elements in a NumPy array. NumPy provides several logarithm functions to calculate different types of logarithms:


Natural Logarithm (numpy.log()): This function computes the natural logarithm (base e) of each element in the input array.

import numpy as np
arr = np.array([1, 2, 3])
# Compute natural logarithm
result = np.log(arr)
print(result) # Output: [0. 0.69314718 1.09861229]


Base-10 Logarithm (numpy.log10()): This function computes the base-10 logarithm of each element in the input array.

import numpy as np
arr = np.array([1, 10, 100])
# Compute base-10 logarithm
result = np.log10(arr)
print(result) # Output: [0. 1. 2.]

General Logorithm: You can compute the logarithm with a specified base using the numpy.log() function and providing the base as the second argument.

import numpy as np
arr = np.array([1, 100, 1000])
# Compute logarithm with base 10
result_base_10 = np.log(arr) / np.log(10)
# Compute logarithm with base 2
result_base_2 = np.log(arr) / np.log(2)
print("Logarithm with base 10:", result_base_10)
print("Logarithm with base 2:", result_base_2)

These logarithm functions are useful for various mathematical and scientific computations, such as data transformation, signal processing, and statistical analysis. They are efficient and vectorized, making them suitable for working with large arrays of data in NumPy.






Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java