# Numpy e^x – Python NumPy expm1() Function

NumPy expm1() Function:

Numpy e^x: The expm1() function of the NumPy module calculates the ex-1, which is e raised to the power of a given number minus 1. Here, e is the natural logarithm’s base, and its value is about 2.718282.

Syntax:

numpy.expm1(a, out=None)

Parameters

a: This is required. It is the array or an object given as input.

out: This is optional. It is the location where the result will be stored. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.

Return Value:

The exponential minus 1( ex-1) value of each element of the given array(a) is returned by the expm1() function of the NumPy module.

## NumPy expm1() Function in Python

Example1

Approach:

• Import numpy module using the import keyword
• Pass some random list as an argument to the array() function of the numpy module to create an array.
• Store it in a variable.
• Print the above-given array.
• Pass the above-given array as an argument to the expm1() function of the numpy module to get the exponential minus 1 (ex-1) values of each element of the given array.
• Store it in another variable.
• Print the exponential minus 1 (ex-1) values of each element of the given array
• The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random list as an argument to the array() function
# of the Numpy module to create an array.
# Store it in a variable.
gvn_arry = np.array([3, 6, 4, 10, 1])
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the expm1() function of the
# numpy module to get the exponential minus 1 (e^x-1) values of each element of
# the given array
# Store it in another variable.
rslt = np.expm1(gvn_arry)
# Print the exponential minus 1 (e^x-1) values of each element of the given array
print("The exponential minus 1 (e^x-1) values of each element of the given array:")
print(rslt)

Output:

The above given array is:
[ 3 6 4 10 1]

The exponential minus 1 (e^x-1) values of each element of the given array:
[1.90855369e+01 4.02428793e+02 5.35981500e+01 2.20254658e+04
1.71828183e+00]

Example2(Plotting a Graph)

Approach:

• Import numpy module using the import keyword
• Import pyplot from the matplotlib module using the import keyword
• Give some random list as static input and store it in a variable.
• Pass the above-given list as an argument to the expm1() function of the numpy module to get the exponential minus 1 (e^x-1) values of each element of the given array.
• Store it in another variable.
• Store the above input array in another variable for plotting the input array vs input array.
• Plot the input array versus input array with some random color and marker values using the plot() function of the matplotlib module
• Plot the output array(e^x-1) versus input array with some other random color and marker values using the plot function of the matplotlib module
• Give the title of the plot using the title() function of the matplotlib module
• Display the plot using the show() function of the matplotlib module.
• The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Import pyplot from the matplotlib module using the import keyword
import matplotlib.pyplot as plt
# Give some random list as static input and store it in a variable.
gvn_arry = [1.3, 1, 2.4, 3.2, 4]
# Pass the above-given list as an argument to the expm1() function of the numpy module to
# get the exponential minus 1 (e^x-1) values of each element of the given array.
# Store it in another variable.
rslt_arry = np.expm1(gvn_arry)
# Store the above input array in another variable for plotting the input array vs input array.
temp_inputarry = [1.3, 1, 2.4, 3.2, 4]
# Plot the input array versus input array with some random color and marker values using
# the plot() function of the matplotlib module
plt.plot(gvn_arry, temp_inputarry, color = 'green', marker = "*")
# Plot the output array(e^x-1) versus input array with some other random color
# and marker values using the plot function of the matplotlib module
plt.plot(rslt_arry, temp_inputarry, color = 'orange', marker = "o")
# Give the title of the plot using the title() function of the matplotlib module
plt.title("Plotting Exponential minus 1 (e^x-1) values:")
plt.xlabel("X")
plt.ylabel("Y")
# Display the plot using the show() function of the matplotlib module.
plt.show()

Output: