.exp()
The .exp()
function in NumPy calculates the exponential of all elements in the input array. The exponential function, .exp(𝑥)
, returns e^x
, where e
is Euler’s number with an approximate value of 2.71828. As a part of the NumPy library, which is widely used for numerical computing in Python, this function is particularly useful in scientific computations where exponential functions are common.
Syntax
numpy.exp(arr, out=None, where=True, casting=‘same_kind’, order=‘K’, dtype=None)
arr
: The input array or list for computing the exponential.out
: The location to store the result. It must be broadcastable to the shape ofarr
.where
: The condition to be checked. WhenTrue
, the function is applied and whenFalse
, the original values are retained.casting
: Controls the type of data casting that may occur.order
: Defines the memory layout order of the result:C
for C-order,F
for Fortran-order,A
for automatic, andK
for input layout.dtype
: Overrides the data type of the resultant array.
Note: In the
.exp()
function, the only mandatory parameter isarr
. All other parameters, includingout
,where
,casting
,order
, anddtype
, are optional and have default values.
Example
Here is an example demonstrating the use of the .exp()
function:
import numpy as np# Create an input arrayarr = np.array([0, 1, 2, 3])# Compute the exponential of each element in the arrayresult = np.exp(arr)# Print the resultprint("Exponential of input array:", result)
The code above produces the following output:
Exponential of input array: [ 1. 2.71828183 7.3890561 20.08553692]
In this example, the .exp()
function is used to compute the exponential of each element in the array [0, 1, 2, 3]
.
Codebyte Example
Here is a working codebyte example demonstrating the .exp()
function in action:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.