BetterDocs
Home
Docs

Creation | np.geomspace()

Method:

np.geomspace(start, stop, num=50, endpoint=True, dtype=np.float64, axis=0)

Generates numbers spaced evenly on a geometric scale.

Returns:

np.ndarray

Parameters:

start: int-

Starting value of the NumPy array.

import numpy as np

# Generate 5 values logarithmically spaced between 1 and 1000
result = np.geomspace(start=1, stop=1000, num=5)
print(result) #Output: [   1.            5.62341325   31.6227766   177.827941   1000.        ]

Firstly, a ratio is calculated using a formula - (stop/start)(1/num-1). The ratio is then used as follows -

result[0] = start # 1

result[1] = result[0] x ratio # 5.62341325

result[2] = result[1] x ratio # 31.6227766

stop: int-

End of the interval value of the NumPy array.

import numpy as np

# Generate 5 values logarithmically spaced between 1 and 10
result = np.geomspace(start=1, stop=10, num=5)
print(result) #Output: [ 1.          1.77827941  3.16227766  5.62341325 10.        ]

If stop > start, an array is returned with data in decreasing order.

If stop < start, an array is returned with data in ascending order.

If stop = start, an array of start is returned.

num: int-

Number of the intervals in the NumPy array.

import numpy as np

# Generate 10 values logarithmically spaced between 1 and 10
result = np.geomspace(start=1, stop=10, num=10)
print(result) 
'''
Output: 
[ 1.          1.29154967  1.66810054  2.15443469  2.7825594   3.59381366
  4.64158883  5.9948425   7.74263683 10.        ]
'''

endpoint: (True or False) Optional-

If endpoint is set to True, stop value is included in the returned NumPy array.

endpoint = True (default) +

endpoint = False +

dtype: np.float64, Optional-

The desired data-type for the NumPy array is inferred from the dtype specified.

import numpy as np

# Generate 5 values logarithmically spaced between 1 and 10
result = np.geomspace(start=1, stop=10, num=5, dtype=np.int32)
print(result) 
'''
Output: 
[ 1  1  3  5 10]
'''

Values: +

By passing the dtype, you are implicitly converting the values to the passed dtype.

axis: int Optional-

The axis in the result to store the samples. Relevant only if start or stop are array-like.

axis = 0 (default) +

axis = -1 +

axis is only useful when dealing with array-like input.

Plays a vital role in transformation of the input along your axis (columns or rows).


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy