numpy.geomspace() in Python
The geomspace() function of Python numpy class returns the numbers spaced equally on a log scale (a geometric progression). This method is similar to numpy.logspace() but with endpoints specified directly.
Syntax
numpy.geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0)
Parameter
start: This parameter represents the starting number of the sequence. stop: It signifies the final value of the sequence unless endpoint is False. num: The num argument represents the number of samples to generate. It is an optional parameter, and its default value is 50. endpoint: It optional parameter which takes Boolean values. If passed true, the stop is the last sample. dtype: This parameter represents the type of output array.
Return
This function returns the ‘ndarray’ where the ‘num’ samples are equally spaced on a log scale.
Example 1
# Python3 Program demonstrate
# numpy.geomspace() function
import numpy as np
print("Matrix:\n", np.geomspace(3.0, 4.0, num = 6), "\n")
# To evaluate sin() in long range
point = np.geomspace(1, 2, 10)
print("Matrix\n", np.sin(point))
Output
Matrix:
[ 3. 3.17767152 3.36586544 3.56520492 3.77635005 4. ]
Matrix:
[ 0.84147098 0.88198596 0.91939085 0.95206619 0.9780296 0.9948976
0.99986214 0.98969411 0.96079161 0.90929743]