numpy.geomspace() returns a set of numbers spaced evenly on a log scale (a geometric progression).
Linspace − It is similar to geomspace, but endpoints specified using the log and base.
Logspace − It is similar to geomspace, but endpoints specified with arithmetic instead of geometric progression.
Syntax
numpy.goemspace(start, stop, num = 50, endpoint = True/False, dtype = None)
Parameters
The above function can accept the following parameters −
start − Start of the sequence; default is zero.
stop − Endpoint of the sequence.
num − Number of elements which are generated between the start and stop sequence.
endpoint − It controls whether the stop value is included in the output array or not. If endpoint=True, then the stop parameter is included as the last item in the nd.array. If endpoint=False, then the stop parameter is not included.
dtype − it describes type of output array.
Example 1
Let us consider the following example −
# Import numpy import numpy as np # geomspace() function x = np.geomspace(1, 2000, num=8) print ("geomspace of X: \n", x)
Output
It will generate the following output −
geomspace of X: [1.00000000e+00 2.96193630e+00 8.77306662e+00 2.59852645e+01 7.69666979e+01 2.27970456e+02 6.75233969e+02 2.00000000e+03]
Example 2
Let us consider the following example −
# Import numpy import numpy as np # geomspace() function x = np.geomspace(2, 800, num = 9, endpoint = False) print ("geomspace of X :\n", x)
Output
The above program will generate the following output −
geomspace of X : [ 2. 3.89177544 7.57295802 14.73612599 28.67484658 55.79803176 108.57670466 211.27807602 411.12341312]
Here, we have taken endpoint=False, hence the stop parameter is not included in the sequence.