Updated May 19, 2023

## Definition of NumPy exponential

NumPy library contains various function exponential is one of them. These functions are used to perform calculations on the array or n-dimensional array. The exponential function calculates the logarithm and exponential value of array elements. In Python, NumPy exponential provides various parts to calculate log and exp values. Positions are listed as loglp, log1, log2, log3 for log. Expml, exp2, exp to calculate an exponential value.

**Syntax:**

To use this exponential function, to need to import numPy library. After importing the package, we can use the different functions to calculate the exponential values.

```
import numPy as myNum
myarr = myNum.array([100, 400, 500, 700, 800])
myNum.exp(myarr)
```

In the above syntax, we are using the exp() function to calculate the exponential value of the array elements.

e.g.

`myNum.exp(your_array)`

In short, we can pass our array inside the exponential function to calculate the values.

### How does Exponential Function Work in NumPy?

Now we know that we use NumPy exponential function to get the exponential value of every element of the array. This array can be of any type single, two, three, or multidimensional array. The exponential function takes two parameters. Some other parameters are also there where and out but we will discuss more about the basic parameter it takes.

`numpy_name.exp(param)`

Here this function takes one parameter named x. This parameter is like the input it takes to calculate the value. We need to pass our array inside the function. This input parameter can accept anything like an array, also. It can get single values as well. There is no restriction, so however we can also be able to calculate the value of a single element if required. To pass any single value, the syntax will look like this see below;

1. With a single value; we will see one practice example to understand it better;

**Syntax:**

`numpy_name.exp(your_value here ..)`

**Example:**

```
import numPy as myNum
myNum.exp(100)
```

So, in this case, we are just passing the single element as the parameter here, so this exp() function will calculate its exponential value.

2. With array as the parameter inside the function; We will also go to see one practice example for better understating;

**Syntax:**

`numpy_name.exp(your_array here ..)`

**Example:**

```
import numPy as myNum
myarr = myNum.array([100, 400, 500, 700, 800])
myNum.exp(myarr)
```

In the above lines of code,, we are creating one array named mayor, which will hold some elements inside it. For creating an array, we are using the array() function provided by the numPy library in Python. Following the exp() function inside this,, we pass our newly created array as the parameter,, and this function will give us the exponential value of this array.

3. With the multi-dimensional array inside the exp() function; we will see syntax for it to understand it better;

**Syntax:**

`numpy_name.exp(your 2d array here ..)`

Now here we have to create one 2d array to work with it. In order to create a 2d array, we have one function called ‘arrang’ provided by the numPy library in Python.

Let’s see one basic structure to create a 2d array using numPy function see below;

**Example:**

```
import numPy as myNum
myArr = myNum.arange(6)
myNum.exp(myArr)
```

In the above example, we are using arrange function to work with a 2d array in Python, but in order to use it, we have to import numPy in our program. This function will create one 2d array for us, followed by the exp() function. we just need to pass the 2d array inside the function to get the exponential values of the array elements.

### Examples of NumPy exponential

Following are the examples are given below:

#### Example #1

In this example, we are creating a single-dimension array and using the exp() function to get the exp values of elements.

**Code:**

```
import numpy as myNum
#creating array using numpy
myarr = myNum.array([4, 9, 2, 5])
#using exp() function to get the value
resultarr = myNum.exp(myarr)
#printing the result
print(resultarr)
```

**Output:**

#### Example #2

In this example, we are creating a three-dimensional array and calculating its value using exp() function from NumPy.

**Code:**

```
import numpy as myNum
#creating array using numpy
myarr1 = myNum.array([4, 9, 2, 5])
myarr2 = myNum.random.randint(0, 5, size = (2, 3, 8))
#using exp() function to get the value
resultarr1 = myNum.exp(myarr1)
resultarr2 = myNum.exp(myarr2)
#printing the result
print(resultarr1)
print(resultarr2)
```

**Output:**

#### Example #3

In this example, we are creating a 2d array, but now we are using exp2() function. To get the exp value of the elements.

**Code:**

```
import numpy as myNum
#creating array using numpy
myarr1 = myNum.array([4, 9, 2, 5])
myarr2 = myNum.random.randint(0, 5, size = (2, 3, 8))
#printing the array value here ..
print(myarr1)
print(myarr2)
#using exp() function to get the value
resultarr1 = myNum.exp2(myarr1)
resultarr2 = myNum.exp2(myarr2)
#printing the result
print(resultarr1)
print(resultarr2)
```

**Output:**

#### Example #4

In this example, we are creating a multi-dimension array but using expm1() function from the exponential function library in Python.

**Code:**

```
import numpy as myNum
#creating array using numpy
myarr1 = myNum.array([4, 9, 2, 5])
myarr2 = myNum.random.randint(0, 5, size = (2, 3, 8))
#printing the array value here ..
print(myarr1)
print(myarr2)
#using expm1() function to get the value
resultarr1 = myNum.expm1(myarr1)
resultarr2 = myNum.expm1(myarr2)
#printing the result
print(resultarr1)
print(resultarr2)
```

**Output:**

#### Example #5

In this example, we are calculating the exp value of the decimal elements by using the exp() function.

**Code:**

```
import numpy as myNum
#creating array using numpy
myarr1 = myNum.array([4, 92.4, 1.0, 3.5, 8.4])
myarr2 = myNum.random.randint(0, 5, size = (2, 3, 8))
#printing the array value here ..
print(myarr1)
print(myarr2)
#using expm1() function to get the value
resultarr1 = myNum.expm1(myarr1)
resultarr2 = myNum.expm1(myarr2)
#printing the result
print(resultarr1)
print(resultarr2)
```

**Output:**

### Conclusion

NumPy library provides various functions that can be used for computation on the array. The exponential function is one of the utilities we can say to get the exp value of the element. By using this, we can get the exp value of a single element as well, not only array specific. So we can use these elements inside an array or a single element.

### Recommend ed Articles

We hope that this EDUCBA information on “NumPy exponential” was beneficial to you. You can view EDUCBA’s recommended articles for more information.