NumPy exp()

The numpy.exp() function calculates the exponential of all elements in the input array. It computes e raised to the power of each element in the input array, where e is Euler’s number, approximately equal to 2.718.

Syntax

</>
Copy
numpy.exp(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)

Parameters

ParameterTypeDescription
xarray_likeInput values. Exponential is calculated for each element.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to compute. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the exponential.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines if subclasses of ndarray are preserved in the output.

Return Value

Returns an array with the exponential of each input element. If the input is a scalar, a scalar is returned.


Examples

1. Calculating the Exponential of a Single Value

In this example, we calculate the exponential of a single numeric value.

</>
Copy
import numpy as np

# Define a single value
value = 1

# Calculate the exponential of the value
result = np.exp(value)

# Print the result
print("Exponential of 1:", result)

Output:

Exponential of 1: 2.718281828459045