NumPy Log
Submitted by moazkhan on Tuesday, July 14, 2020 - 15:21.
In this tutorial you will learn:
- What is a logarithm?
- Implementation of Log with different bases in Python
- Python Syntax
Logarithm
In order to simplify the calculations, Logarithms were introduced in 1614 by John Napier. Logarithm is inverse to an exponential function. Lets take a number x, its logarithm is the exponent to which another fixed number, the base b must be raised to produce x. The logarithm with base 10 is called as the common logarithm and it has many applications in the domain of engineering and science. There are other logarithms as well with different bases used in mathematics, physics and sciences.Implementation of Logarithms with different bases in Python
In NumPy there are following 3 functions for the implementation of logarithms- log()
- log2()
- log10()
- #importing the numpy lib
- import numpy as n
- #Declaring a variable num with value 2.23
- num=2.23
- #taking natural log of 2.23 using log function
- print('Result of taking natural log of 2.23:')
- print(n.log(num))
- #importing the numpy lib
- import numpy as n
- #Declaring a variable 'num' with value 1.98
- num=1.98
- #taking log at base 10 of 1.98 using log10() function
- print('Result of taking log at base 10 of 1.98:')
- print(n.log10(num))
- #importing the numpy lib
- import numpy as n
- #Declaring a variable 'num' with value 5.44
- num=5.44
- #taking log at base 2 of 5.44 using log2() function
- print('Result of taking log at base 2 of 5.44:')
- print(n.log2(num))
Add new comment
- 105 views