Here, I’ll show you a few examples of how to use numpy.exp. Now that I’ve explained the syntax, let’s take a look at some examples. You can actually leave it out and just type the name of the input array inside of the parenthesis. You must provide an input here.Īlso, you don’t explicitly need to type x =. Note that an input to this parameter is required. So you can actually use Python lists and other array-like objects as inputs to the x parameter. Technically, this input will accept NumPy arrays, but also single numbers (integers or floats) or array-like objects. The x = parameter enables you to provide the inputs to the np.exp() function. There are a few other parameters like out and where, but they are less commonly used, so we won’t cover them here. There’s really only 1 parameter that we’re going to talk about, and that’s the x parameter. Having said that though, let’s quickly talk about the parameters of np.exp. It’s possibly one of the simplest NumPy functions.Įssentially, you call the function with the code np.exp() and then inside of the parenthesis is a parameter that enables you to provide the inputs to the function. NumPy exponential syntaxĪs I mentioned earlier, the syntax of the NumPy exponential function is extremely simple. I’ll show you this specifically when we look at some examples. That will only work properly though if you import NumPy with the code import numpy as np. I just want to point this out, because in this tutorial (and specifically in this section about the syntax) I’m referring to NumPy as np. You can do it with the code import numpy as np. Technically speaking, we give NumPy this nickname when we import the NumPy module. A quick noteĪ very common convention in NumPy syntax is to give the NumPy module the alias “ np“. The syntax of np.exp (AKA, the NumPy exponential function) is extremely simple.īefore I show it to you though, I want to make an important point. So now that you know what the function does, let’s take a look at the actual syntax. So essentially, the np.exp function is useful when you need to compute for a large matrix of numbers. Like all of the NumPy functions, it is designed to perform this calculation with NumPy arrays and array-like structures. … where is the mathematical constant that’s approximately equal to 2.71828 (AKA, Euler’s number). The NumPy exponential function (AKA, numpy.exp) is a function for calculating the following: This is where the numpy.exp function comes in.Ī quick introduction to the NumPy exponential function NumPy also has tools for performing common mathematical computations. So you can use NumPy to change the shape of a NumPy array, or to concatenate two NumPy arrays together. NumPy also has tools for reshaping NumPy arrays. NumPy has functions for calculating means of a NumPy array, calculating maxima and minima, etcetera. In addition to providing functions to create NumPy arrays, NumPy also provides tools for manipulating and working with NumPy arrays.įor example, there are tools for calculating summary statistics. NumPy provides tools for manipulating numeric data Many NumPy functions simply enable you to create types of NumPy arrays, like the NumPy zeros functions, which creates NumPy arrays filled with zeroes and NumPy ones, which creates NumPy arrays filled with ones. NumPy even allows for multi-dimensional arrays. Or they can be more complicated, like a 2-dimensional array: They can be simple, like a 1-dimensional array: You can think of these arrays like row-and-column structures, or like matrices from linear algebra. NumPy is essentially a Python module that deals with arrays of numeric data. The NumPy module is very important for data science in Python, so you should understand what it is and what it does. If you’re just getting started with data science in Python, you’ve probably heard about NumPy, but you might not know exactly what it is. Everything will make more sense that way.īefore we get into the specifics of the numpy.exp function, let’s quickly review NumPy. On the other hand, if you’re just getting started with NumPy, I strongly suggest that you read the whole tutorial. So if you have something that you’re trying to quickly understand about numpy.exp, you can just click to the correct section. You can click on any of the links above, and it will take you to the appropriate spot in the tutorial. We’ll start with a quick review of the NumPy module, then explain the syntax of np.exp, and then move on to some examples. With that in mind, this tutorial will carefully explain the numpy.exp function. It seems particularly confusing for beginners. This is a very simple function to understand, but it confuses many people because the documentation is a little confusing. This tutorial will explain how to use the NumPy exponential function, which syntactically is called np.exp.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |