.exp()

Anonymous contributor's avatar
Anonymous contributor
Published Jun 13, 2024
Contribute to Docs

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 of arr.
  • where: The condition to be checked. When True, the function is applied and when False, 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, and K for input layout.
  • dtype: Overrides the data type of the resultant array.

Note: In the .exp() function, the only mandatory parameter is arr. All other parameters, including out, where, casting, order, and dtype, 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 array
arr = np.array([0, 1, 2, 3])
# Compute the exponential of each element in the array
result = np.exp(arr)
# Print the result
print("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:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python:NumPy on Codecademy