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
| Parameter | Type | Description |
|---|---|---|
x | array_like | Input values. Exponential is calculated for each element. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to compute. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the exponential. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines 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
