Skip to content

Numpy exp() function

  • by

The numpy exp() function is used to calculate the exponential of an array or scalar value. It returns an array of the same shape as the input array, with each element replaced by its exponential value.

Numpy exp() function example

Simple example code.

import numpy as np
from matplotlib import pyplot as plt

# single element

# multiple elements of 1-d array
arr = [2, 5, 8]
res = np.exp(arr)

# 2-D numpy array elements
arr = np.array([[4, 6, 3, 7], [8, 5, 2, 9]])
res = np.exp(arr)


Numpy exp() function

Use numpy.exp() function to the graphical representation

import numpy as np
from matplotlib import pyplot as plt

# Use numpy.exp() function to graphical representation
arr = [1, 1.4, 1.8, 2, 2.6, 3]
out_array = np.exp(arr)
arr2 = [1, 1.3, 1.6, 2.3, 2.8, 3]
plt.plot(arr, arr2, color='green', marker="*")

# Yellow for numpy.exp()
plt.plot(out_array, arr2, color='yellow', marker="o")


numpy exp() function to graphical representation

What exactly does numpy.exp() do?

Answer: The exponential function is e^x where e is a mathematical constant called Euler’s number, approximately 2.718281. This value has a close mathematical relationship with pi and the slope of the curve e^x is equal to its value at every point. np.exp() calculates e^x for each value of x in your input array.

exp(x) = e^x where e= 2.718281(approx)

Do comment if you have any doubts or suggestions on this Python Numpy function

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading