---
title: logspace()
url: https://docs.vultr.com/python/third-party/numpy/logspace
description: Generate Logarithmic Spaced Array
publish_date: 2024-11-14T21:20:00.071984Z
last_updated: 2024-11-14T21:20:00.071984Z
header_image: https://assets.vultrdevrel.com/docs-main-doc-assets-1/collection-items/850/6d88a4ec-8dfe-453b-90c0-d07266c91f9f.jpg
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

# Python Numpy logspace() - Generate Logarithmic Spaced Array

## Introduction
The `numpy.logspace()` function is a powerful tool from the NumPy library that allows for the creation of arrays with logarithmically spaced values between a specified start point and an end point. This function is highly beneficial in scientific computing where logarithmic scales are commonplace, such as in frequencies for signal processing or in scales for graphical representations.

In this article, you will learn how to generate logarithmically spaced arrays using the `numpy.logspace()` function. You'll explore various parameters that can be adjusted to tailor the output array, understand the key differences between `logspace()` and other similar functions like `linspace()`, and see practical examples of its applications.

## Understanding numpy.logspace()

### Basic Usage of logspace()
1. Import the NumPy library.
1. Use the `logspace()` function to create an array.

    ```python
    import numpy as np
    log_array = np.logspace(1, 10, num=10, base=10)
    print(log_array)
    ```

    This example creates an array of 10 values logarithmically spaced between 10^1 and 10^10.

### Parameters of logspace()
1. `start`: The start point of the intervals, as the power of the base (default base is 10).
1. `stop`: The end point of the intervals, as the power of the base.
1. `num`: Number of samples to generate. Default is 50.
1. `endpoint`: If `True` (default), `stop` is the last sample. Otherwise, it is not included.
1. `base`: The base of the logarithm (default is 10).
1. `dtype`: The type of the output array; if not specified, infers from other input types.

### Using Different Bases
1. Adjust the base parameter to use logarithmic scales other than 10.

    ```python
    log_array_base2 = np.logspace(1, 10, num=10, base=2)
    print(log_array_base2)
    ```

    This generates an array with values spaced according to the powers of 2.

## Advanced Applications of logspace()

### Generating Frequency Bands
1. Use `logspace()` to create frequency bands which are common in signal processing.

    ```python
    frequencies = np.logspace(0.1, 2, num=20, base=10)
    print(frequencies)
    ```

    This code snippet generates 20 logarithmic spaced points between 10^0.1 and 10^2, useful for processing logarithmic scales in audio signals.

### Comparing logspace() and linspace()
1. Understand that while `logspace()` deals with logarithmic intervals, `linspace()` generates linear intervals.

    ```python
    linear_space = np.linspace(10, 1000, num=10)
    print(linear_space)
    ```

    Compare the output with `logspace()` to appreciate the difference in interval distribution.

## Conclusion
The `numpy.logspace()` function is indispensable for creating logarithmic spaced arrays, particularly useful in fields like signal processing and graphical plotting where such scaling is required. By understanding how to manipulate various parameters like `base`, `num`, and setting `endpoint`, you can effectively use `logspace()` for a wide range of applications that require non-linear spacing. Experiment with these settings to match the specific needs of your project and integrate `logspace()` effectively into your data manipulation toolbox.