NumPy logspace() function
In this tutorial, we will cover
numpy.logspace() function of the Numpy library.
numpy.logspace() function in Numpy is used to create an array by using the numbers that are evenly separated on a log scale.
The syntax to use this function is as follows:
numpy.logspace(start, stop, num, endpoint, base, dtype)
The parameters of this function are as follows:
This parameter is used to represent the starting value of the interval in the base.
This parameter is used to represent the stopping value of the interval in the base.
This parameter is used to indicate the number of values between the range.
This parameter's value is in boolean and it is used to make the value represented by stop as the last value of the interval.
This parameter is used to represent the base of the log space.
This parameter is used to represent the data type of the array items.
This function will return the array in the specified range.
Now it's time to look at a few examples in order to gain an understanding of this function.
Below we have the code snippet where we will use this function:
import numpy as np arr = np.logspace(20, 30, num = 7,base = 4, endpoint = True) print("The array over the given range is ") print(arr)
The array over the given range is
[1.09951163e+12 1.10823828e+13 1.11703419e+14 1.12589991e+15
1.13483599e+16 1.14384301e+17 1.15292150e+18]
In the example given below we will cover the graphical representation of
numpy.logspace() function using matplotlib:
import numpy as np import matplotlib.pyplot as plt N = 20 x1 = np.logspace(0.1, 1, N, endpoint=True) x2 = np.logspace(0.1, 1, N, endpoint=False) y = np.zeros(N) plt.plot(x1, y, 'o') plt.plot(x2, y + 0.8, 'o') plt.ylim([-0.5, 1]) plt.show()
Output of the following code:
In this tutorial, we covered
numpy.logspace() function of the Numpy library. We learned its syntax, parameters as well as the value returned by this function along with multiple code example.