search
Search
menu search toc more_vert
Guest 0reps
Thanks for the thanks!
close
account_circle
Profile
exit_to_app
Sign out
help Ask a question
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview Doc Search Code Search Beta SORRY NOTHING FOUND!
mic
Start speaking... Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
A
A
brightness_medium
share
arrow_backShare Twitter Facebook

# NumPy | geomspace method

NumPy
chevron_right
Documentation
schedule Jul 1, 2022
Last updated
local_offer PythonNumPy
Tags
expand_more

Numpy's `geomspace(~)` method creates a Numpy array with values that follow a geometric sequence.

# Parameters

1. `start` | `number`

The starting value of the Numpy array.

2. `stop` | `number`

The ending value of the Numpy array. This is inclusive.

3. `num` | `int` | `optional`

The number of samples you want to generate. By default, `num=50`.

4. `endpoint` | `boolean` | `optional`

If set to `True`, then stop will be the last value of the Numpy array. By default, `endpoint=False`.

5. `dtype` | `string` or `type` | `optional`

The desired data type for the Numpy array. This overrides the default behavior of using the same data-type as the source array.

# Return value

A Numpy array with values that follow a geometric sequence.

# Examples

## Basic usage

Starting from a value of 1, and ending with a value of 64, create a Numpy array that follows a geometric sequence with 4 numbers:

``` np.geomspace(1, 64, num=4) # By default, num=50 array([ 1., 4., 16., 64.]) ```

Notice how the end value (i.e. the second parameter) is inclusive.

Here, the common ratio is 4, so the numbers in the array are generated like so:

``` 1 * 4 = 44 * 4 = 1616 * 4 = 64 ```

## Excluding the endpoint

We set `endpoint=False`, like follows:

``` np.geomspace(1, 64, 4, endpoint=False) array([ 1. , 2.82842712, 8. , 22.627417 ]) ```

## Explicit typing

We set `dtype=float` to obtain a Numpy array of type float.

``` np.geomspace(1, 64, 4, dtype=float) array([ 1. , 2.82842712, 8. , 22.627417 ]) ```
mail