What is the geomspace() function from NumPy in Python?
Overview
The geomspace() function in Python returns numbers that are evenly spaced on a geometric progression.
Syntax
numpy.geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0)
Required parameters
The geomspace() function takes the following parameter values:
start: This represents the starting value of the sequence.stop: This represents the final value of the sequence, unless theendpointparameter isFalse.dtype: This represents the data type of the output array.
Optional parameters
num: This represents the number of samples to generate.endpoint: This takes a boolean value. IfTrue, the value of thestopparameter is the last sample. Otherwise, it is not included. It isTrueby default.axis: This represents the axis in the result to store the samples. It is0by default.
Return value
The geomspace() function returns number samples equally spaced on a log scale.
Example
import numpy as np# creating the arraymyarray = np.geomspace(1, 10, num=10, endpoint = True, dtype = float, axis = 0)print(myarray)
Explanation
- Line 1: We import the
numpylibrary. - Line 4: We create an array with samples that starts from
1, stops at10, with aTruevalue for its endpoint (thestopvalue is included),floatdata type and a default value for theaxis. We assign the result to a variablemyarray. - Line 6: We print the array
myarray.