# Python Numpy Exponential Functions

The Python numpy module has exponential functions used to calculate the exponential and logarithmic values of a single, two, and three-dimensional arrays. And they are exp, exp2, expm1, log, log2, log10, and log1p. You can use Python numpy Exponential Functions, such as exp, exp2, and expm1, to find exponential values. The following four functions log, log2, log10, and log1p in Python numpy module calculates the logarithmic values.

## Python numpy Exponential Functions

The following list of examples helps understand the numpy Exponential Functions

### Python numpy exp

The Python numpy exp function calculates and returns the exponential value of each item in a given array. First, we declared a single-dimensional array, two dimensional and three-dimensional random arrays of different sizes. Next, we used the Python numpy exp function on those arrays to calculate exponential values.

```import numpy as np

arr = np.array([0, 1, 2, 3, 4])
print(arr)
print('---Exponential Values of arr---')
print(np.exp(arr))

arr1 = np.random.randint(0, 6, size = (3, 4))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Exponential Values of Two Dimensional Random Array---')
print(np.exp(arr1))

arr2 = np.random.randint(0, 10, size = (2, 3, 4))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Exponential Values of Three Dimensional Random Array---')
print(np.exp(arr2))```

### Python numpy exp2

The Python numpy exp2 function calculates 2**p, where p means each item in a given numpy array. Here, we used the numpy exp2 function on those arrays to calculate exponential values. For example, exp2(3) = 2 **3 => 2 * 2 * 2 = 8.

```import numpy as np

arr = np.array([0, 1, 2, 3, 4])
print(arr)
print('---Exponential Values of arr---')
print(np.exp2(arr))

arr1 = np.random.randint(0, 6, size = (3, 7))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Exponential Values of Two Dimensional Random Array---')
print(np.exp2(arr1))

arr2 = np.random.randint(0, 10, size = (2, 3, 8))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Exponential Values of Three Dimensional Random Array---')
print(np.exp2(arr2))```

### Python numpy expm1

The Python numpy expm1 function calculates exponential values  – 1 of all the items in a given array. It means, expm1(array_name) =  exp(array_name) – 1. Here, we used the Python numpy expm1 function to calculate exponential values.

```import numpy as np

arr = np.array([0, 1, 2, 3, 4])
print(arr)
print('---Exponential Values of arr---')
print(np.expm1(arr))

arr1 = np.random.randint(0, 6, size = (3, 5))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Exponential Values of Two Dimensional Random Array---')
print(np.expm1(arr1))

arr2 = np.random.randint(0, 10, size = (2, 3, 4))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Exponential Values of Three Dimensional Random Array---')
print(np.expm1(arr2))```

## Python numpy Logarithmic Functions

The following examples helps understand the numpy logarithmic Functions

### Python numpy log

The Python numpy log function calculates the natural logarithmic value of each item in a given array. We declared 1D, 2D, and 3D random arrays of different sizes. Next, we used the Python numpy log function on those arrays to calculate logarithmic values.

```import numpy as np

arr = np.array([1, 2, 3, 4])
print(arr)
print('---Logarithmic Values of arr---')
print(np.log(arr))

arr1 = np.random.randint(1, 15, size = (3, 4))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Logarithmic Values of Two Dimensional Random Array---')
print(np.log(arr1))

arr2 = np.random.randint(16, 60, size = (2, 3, 4))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Logarithmic Values of Three Dimensional Random Array---')
print(np.log(arr2))```

### Python Numpy log2

The Python Numpy log2 function calculates the base 2 logarithmic value of all the items in a given array. Using the Python Numpy log2 function on 1D, 2D, and 3D arrays to calculate base 2 logarithmic values.

```import numpy as np

arr = np.array([1, 2, 3, 4, 5])
print(arr)
print('---Base 2 Logarithmic Values of arr---')
print(np.log2(arr))

arr1 = np.random.randint(1, 15, size = (3, 4))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Base 2 Logarithmic Values of Random Two Dimensional Array---')
print(np.log2(arr1))

arr2 = np.random.randint(16, 60, size = (2, 3, 4))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Base 2 Logarithmic Values of Random Three Dimensional Array---')
print(np.log2(arr2))```

### Python numpy log10

The Python numpy log10 function calculates the base 10 logarithmic value of all the array items in a given array. We used the Python numpy log10 function on 1D, 2D, and 3D arrays to calculate base 10 logarithmic values.

```import numpy as np

arr = np.array([1, 2, 3, 4, 5])
print(arr)
print('---Base 10 Logarithmic Values of arr---')
print(np.log10(arr))

arr1 = np.random.randint(1, 15, size = (3, 5))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---Base 10 Logarithmic Values of Random Two Dimensional Array---')
print(np.log10(arr1))

arr2 = np.random.randint(25, 180, size = (2, 3, 5))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---Base 10 Logarithmic Values of Random Three Dimensional Array---')
print(np.log10(arr2))```

### Python numpy log1p

The Python numpy log1p function calculates the natural logarithmic value of 1 plus all the array items in a given array. I mean log1p also called log(1 + array_name). In this example, we used the Python numpy log1p function on 1D, 2D and 3D random arrays to calculate natural logarithmic values.

```import numpy as np

arr = np.array([1, 2, 3, 4, 5])
print(arr)
print('---log1p Values of arr---')
print(np.log1p(arr))

arr1 = np.random.randint(0, 15, size = (3, 5))
print('\n-----Two Dimensional Random Array----')
print(arr1)
print('---log1p Values of Random Two Dimensional Array---')
print(np.log1p(arr1))

arr2 = np.random.randint(25, 380, size = (2, 3, 5))
print('\n-----Three Dimensional Array----')
print(arr2)
print('---log1p Values of Random Three Dimensional Array---')
print(np.log1p(arr2))```