Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

numpy
python
function
communitycreator

What is the geomspace() function from NumPy in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 the endpoint parameter is False.
  • 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. If True, the value of the stop parameter is the last sample. Otherwise, it is not included. It is True by default.
  • axis: This represents the axis in the result to store the samples. It is 0 by default.

Return value

The geomspace() function returns number samples equally spaced on a log scale.

Example

import numpy as np
# creating the array
myarray = np.geomspace(1, 10, num=10, endpoint = True, dtype = float, axis = 0)
print(myarray)
Implementing the geomspace() function

Explanation

  • Line 1: We import the numpy library.
  • Line 4: We create an array with samples that starts from 1, stops at 10, with a True value for its endpoint (the stop value is included), float data type and a default value for the axis. We assign the result to a variable myarray.
  • Line 6: We print the array myarray.

RELATED TAGS

numpy
python
function
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring