﻿ NumPy: Compute e^x, element-wise of a given array - w3resource

# NumPy: Compute e^x, element-wise of a given array

## NumPy Mathematics: Exercise-31 with Solution

Write a NumPy program to compute ex, element-wise of a given array.

Sample Solution:-

Python Code:

``````import numpy as np
x = np.array([1., 2., 3., 4.], np.float32)
print("Original array: ")
print(x)
print("\ne^x, element-wise of the said:")
r = np.exp(x)
print(r)
```
```

Sample Output:

```Original array:
[1. 2. 3. 4.]

e^x, element-wise of the said:
[ 2.7182817  7.389056  20.085537  54.59815  ]
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

```str="+++Welcome python+++"
str.strip()

print(str)```

Output:

`+++Welcome python+++`