numpy.exp(array, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : This mathematical function helps user to calculate exponential of all the elements in the input array. Parameters :
array : [array_like]Input array or object whose elements, we need to test.
out : [ndarray, optional]Output array with same dimensions as Input array,
placed with result.
**kwargs : Allows you to pass keyword variable length of argument to a function.
It is used when we want to handle named argument in a function.
where : [array_like, optional]True value means to calculate the universal
functions(ufunc) at that position, False value means to leave the
value in the output alone.
Return :
An array with exponential of all elements of input array.
Code 1 : Working
Python
# Python program explaining
# exp() function
import numpy as np
in_array = [1, 3, 5]
print ("Input array : ", in_array)
out_array = np.exp(in_array)
print ("Output array : ", out_array)
Output :
Input array : [1, 3, 5]
Output array : [ 2.71828183 20.08553692 148.4131591 ]
Code 2 : Graphical representation
Python
# Python program showing
# Graphical representation of
# exp() function
import numpy as np
import matplotlib.pyplot as plt
in_array = [1, 1.2, 1.4, 1.6, 1.8, 2]
out_array = np.exp(in_array)
y = [1, 1.2, 1.4, 1.6, 1.8, 2]
plt.plot(in_array, y, color = 'blue', marker = "*")
# red for numpy.exp()
plt.plot(out_array, y, color = 'red', marker = "o")
plt.title("numpy.exp()")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
Output :
References : https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.exp.html .
numpy.exp() is a function in the Python NumPy library that calculates the exponential value of an input array. It returns an array with the exponential value of each element of the input array.
The syntax for using numpy.exp() is as follows:
import numpy as np
np.exp(x)
Here, x is the input array or scalar value whose exponential value is to be calculated. The function returns an array with the same shape as x, with the exponential value of each element.
Examples:
Python3
import numpy as np
# Calculating the exponential value of a scalar
exp_val = np.exp(3)
print(exp_val) # Output: 20.085536923187668
# Calculating the exponential value of an array
x = np.array([1, 2, 3])
exp_arr = np.exp(x)
print(exp_arr) #
Output: [ 2.71828183 7.3890561 20.08553692]
In the above example, we calculate the exponential value of a scalar 3 using np.exp(3), which returns 20.085536923187668. We also calculate the exponential value of an array [1, 2, 3] using np.exp(x), which returns [2.71828183, 7.3890561, 20.08553692].
Advantages of numpy.exp() function in Python:
- Fast computation: numpy.exp() function is highly optimized for fast computation, which makes it suitable for handling large datasets and complex calculations in scientific computing and data analysis.
- Versatility: numpy.exp() function can be used with a wide range of input types, including scalars, arrays, and matrices.
- Mathematical accuracy: numpy.exp() function provides high mathematical accuracy for calculating exponential values, which makes it useful in numerical simulations and scientific experiments.
- Integration with other NumPy functions: numpy.exp() function can be easily integrated with other NumPy functions and libraries, allowing for more complex calculations and data analysis.
Disadvantages of numpy.exp() function in Python:
- Potential for numerical overflow or underflow: Since numpy.exp() calculates exponential values, it has the potential for numerical overflow or underflow when dealing with very large or very small numbers. This can lead to inaccurate results or errors in some cases.
- Limited functionality: While numpy.exp() function is useful for calculating exponential values, it has limited functionality compared to other more specialized libraries and functions for mathematical operations and data analysis.
- Requires NumPy library: To use numpy.exp() function, you need to have the NumPy library installed and imported in your Python environment, which can add some overhead to your code and may not be suitable for certain applications.
Similar Reads
Python Tutorial | Learn Python Programming Language
Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
10 min read
Python Interview Questions and Answers
Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
7 min read
Python OOPs Concepts
Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
TCP/IP Model
The TCP/IP model (Transmission Control Protocol/Internet Protocol) is a four-layer networking framework that enables reliable communication between devices over interconnected networks. It provides a standardized set of protocols for transmitting data across interconnected networks, ensuring efficie
7 min read
Python Projects - Beginner to Advanced
Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions
Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs
Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Basics of Computer Networking
A computer network is a collection of interconnected devices that share resources and information. These devices can include computers, servers, printers, and other hardware. Networks allow for the efficient exchange of data, enabling various applications such as email, file sharing, and internet br
14 min read
Unified Modeling Language (UML) Diagrams
Unified Modeling Language (UML) is a general-purpose modeling language. The main aim of UML is to define a standard way to visualize the way a system has been designed. It is quite similar to blueprints used in other fields of engineering. UML is not a programming language, it is rather a visual lan
14 min read