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("\ne^x, element-wise of the said:")
r = np.exp(x)

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.

Previous: Write a NumPy program to calculate the difference between neighboring elements, element-wise, and prepend [0, 0] and append[200] to a given array.

Next: Write a NumPy program to calculate exp(x) - 1 for all elements in a given array.

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+++"



+++Welcome python+++