# Return evenly spaced numbers on a geometric progression and do not set the endpoint in Numpy

NumpyServer Side ProgrammingProgramming

To return evenly spaced numbers on a geometric progression, use the numpy.geomspace() method in Python Numpy −

• The 1st parameter is the "start" i.e. the start of the sequence
• The 2nd parameter is the "end" i.e. the end of the sequence
• The 3rd parameter is the "num" i.e. the number of samples to generate. Default is 50.
• The 4th parameter is the "endpoint". If True, stop is the last sample. Otherwise, it is not included. Default is True.

The start is the starting value of the sequence. The stop if the final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num) are returned. The endpoint, if true, stop is the last sample. Otherwise, it is not included. Default is True.

The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.

## Steps

At first, import the required library −

import numpy as np

To return evenly spaced numbers on a geometric progression, use the numpy.geomspace() method −

arr = np.geomspace(10, 10000, num = 3, endpoint = False)
print("Array...
", arr)

Get the array type −

print("
Type...
", arr.dtype)

Get the dimensions −

print("
Dimensions...
",arr.ndim)

Get the shape −

print("
Shape...
",arr.shape)


Get the number of elements −

print("
Number of elements...
",arr.size)

## Example

import numpy as np

# To return evenly spaced numbers on a geometric progression, use the numpy.geomspace() method in Python Numpy
# The 1st parameter is the "start" i.e. the start of the sequence
# The 2nd parameter is the "end" i.e. the end of the sequence
# The 3rd parameter is the "num" i.e the number of samples to generate. Default is 50.
# The 4th parameter is the "endpoint". If True, stop is the last sample. Otherwise, it is not included. Default is True.
arr = np.geomspace(10, 10000, num = 3, endpoint = False)
print("Array...
", arr)

# Get the array type
print("
Type...
", arr.dtype)

# Get the dimensions
print("
Dimensions...
",arr.ndim)

# Get the shape
print("
Shape...
",arr.shape)

# Get the number of elements
print("
Number of elements...
",arr.size)

## Output

Array...
[ 10. 100. 1000.]

Type...
float64

Dimensions...
1

Shape...
(3,)

Number of elements...
3
Updated on 16-Feb-2022 10:18:22

Advertisements