# NumPy Log

## 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()

We can also create a log function for any base as per the requirement of the programmer. We will comprehend each of the function using the example for each. In each example we will be taking the log of different numbers with different bases, however we can also take the logs of complete arrays with a single line of code.
log() function is used to take the natural log or log at base e of any input number. In this example we are taking the natural log of 2.23

`#importing the numpy libimport numpy as n#Declaring a variable num with value 2.23num=2.23#taking natural log of 2.23 using log functionprint('Result of taking natural log of 2.23:')print(n.log(num))`

log10() is the function which is used to take the log at the base 10 of the input number. In this example we are taking log to the base 10 of 1.98
`#importing the numpy libimport numpy as n#Declaring a variable 'num' with value 1.98num=1.98#taking log at base 10 of 1.98 using log10() functionprint('Result of taking log at base 10 of 1.98:')print(n.log10(num))`

In this example we will be taking log at base 2 using function log2() of the number 5.44
`#importing the numpy libimport numpy as n#Declaring a variable 'num' with value 5.44num=5.44#taking log at base 2 of 5.44 using log2() functionprint('Result of taking log at base 2 of 5.44:')print(n.log2(num))`

### Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.