
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy Arrays
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy Creating and Manipulating Arrays
- NumPy - Array Creation Routines
- NumPy - Array Manipulation
- NumPy - Array from Existing Data
- NumPy - Array From Numerical Ranges
- NumPy - Iterating Over Array
- NumPy - Reshaping Arrays
- NumPy - Concatenating Arrays
- NumPy - Stacking Arrays
- NumPy - Splitting Arrays
- NumPy - Flattening Arrays
- NumPy - Transposing Arrays
- NumPy Indexing & Slicing
- NumPy - Indexing & Slicing
- NumPy - Indexing
- NumPy - Slicing
- NumPy - Advanced Indexing
- NumPy - Fancy Indexing
- NumPy - Field Access
- NumPy - Slicing with Boolean Arrays
- NumPy Array Attributes & Operations
- NumPy - Array Attributes
- NumPy - Array Shape
- NumPy - Array Size
- NumPy - Array Strides
- NumPy - Array Itemsize
- NumPy - Broadcasting
- NumPy - Arithmetic Operations
- NumPy - Array Addition
- NumPy - Array Subtraction
- NumPy - Array Multiplication
- NumPy - Array Division
- NumPy Advanced Array Operations
- NumPy - Swapping Axes of Arrays
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Element-wise Array Comparisons
- NumPy - Filtering Arrays
- NumPy - Joining Arrays
- NumPy - Sort, Search & Counting Functions
- NumPy - Searching Arrays
- NumPy - Union of Arrays
- NumPy - Finding Unique Rows
- NumPy - Creating Datetime Arrays
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy Sorting and Advanced Manipulation
- NumPy - Sorting Arrays
- NumPy - Sorting along an axis
- NumPy - Sorting with Fancy Indexing
- NumPy - Structured Arrays
- NumPy - Creating Structured Arrays
- NumPy - Manipulating Structured Arrays
- NumPy - Record Arrays
- Numpy - Loading Arrays
- Numpy - Saving Arrays
- NumPy - Append Values to an Array
- NumPy - Swap Columns of Array
- NumPy - Insert Axes to an Array
- NumPy Handling Missing Data
- NumPy - Handling Missing Data
- NumPy - Identifying Missing Values
- NumPy - Removing Missing Data
- NumPy - Imputing Missing Data
- NumPy Performance Optimization
- NumPy - Performance Optimization with Arrays
- NumPy - Vectorization with Arrays
- NumPy - Memory Layout of Arrays
- Numpy Linear Algebra
- NumPy - Linear Algebra
- NumPy - Matrix Library
- NumPy - Matrix Addition
- NumPy - Matrix Subtraction
- NumPy - Matrix Multiplication
- NumPy - Element-wise Matrix Operations
- NumPy - Dot Product
- NumPy - Matrix Inversion
- NumPy - Determinant Calculation
- NumPy - Eigenvalues
- NumPy - Eigenvectors
- NumPy - Singular Value Decomposition
- NumPy - Solving Linear Equations
- NumPy - Matrix Norms
- NumPy Element-wise Matrix Operations
- NumPy - Sum
- NumPy - Mean
- NumPy - Median
- NumPy - Min
- NumPy - Max
- NumPy Set Operations
- NumPy - Unique Elements
- NumPy - Intersection
- NumPy - Union
- NumPy - Difference
- NumPy Random Number Generation
- NumPy - Random Generator
- NumPy - Permutations & Shuffling
- NumPy - Uniform distribution
- NumPy - Normal distribution
- NumPy - Binomial distribution
- NumPy - Poisson distribution
- NumPy - Exponential distribution
- NumPy - Rayleigh Distribution
- NumPy - Logistic Distribution
- NumPy - Pareto Distribution
- NumPy - Visualize Distributions With Sea born
- NumPy - Matplotlib
- NumPy - Multinomial Distribution
- NumPy - Chi Square Distribution
- NumPy - Zipf Distribution
- NumPy File Input & Output
- NumPy - I/O with NumPy
- NumPy - Reading Data from Files
- NumPy - Writing Data to Files
- NumPy - File Formats Supported
- NumPy Mathematical Functions
- NumPy - Mathematical Functions
- NumPy - Trigonometric functions
- NumPy - Exponential Functions
- NumPy - Logarithmic Functions
- NumPy - Hyperbolic functions
- NumPy - Rounding functions
- NumPy Fourier Transforms
- NumPy - Discrete Fourier Transform (DFT)
- NumPy - Fast Fourier Transform (FFT)
- NumPy - Inverse Fourier Transform
- NumPy - Fourier Series and Transforms
- NumPy - Signal Processing Applications
- NumPy - Convolution
- NumPy Polynomials
- NumPy - Polynomial Representation
- NumPy - Polynomial Operations
- NumPy - Finding Roots of Polynomials
- NumPy - Evaluating Polynomials
- NumPy Statistics
- NumPy - Statistical Functions
- NumPy - Descriptive Statistics
- NumPy Datetime
- NumPy - Basics of Date and Time
- NumPy - Representing Date & Time
- NumPy - Date & Time Arithmetic
- NumPy - Indexing with Datetime
- NumPy - Time Zone Handling
- NumPy - Time Series Analysis
- NumPy - Working with Time Deltas
- NumPy - Handling Leap Seconds
- NumPy - Vectorized Operations with Datetimes
- NumPy ufunc
- NumPy - ufunc Introduction
- NumPy - Creating Universal Functions (ufunc)
- NumPy - Arithmetic Universal Function (ufunc)
- NumPy - Rounding Decimal ufunc
- NumPy - Logarithmic Universal Function (ufunc)
- NumPy - Summation Universal Function (ufunc)
- NumPy - Product Universal Function (ufunc)
- NumPy - Difference Universal Function (ufunc)
- NumPy - Finding LCM with ufunc
- NumPy - ufunc Finding GCD
- NumPy - ufunc Trigonometric
- NumPy - Hyperbolic ufunc
- NumPy - Set Operations ufunc
- NumPy Useful Resources
- NumPy - Quick Guide
- NumPy - Cheatsheet
- NumPy - Useful Resources
- NumPy - Discussion
- NumPy Compiler
Numpy logspace() Function
The Numpy logspace() function is used to generate an array of numbers spaced evenly on a logarithmic scale. It is useful for creating ranges that increase exponentially rather than linearly, which is common in many scientific and engineering applications.
Using numpy.logspace(), we can specify the starting and ending exponents, as well as the base of the logarithm. This is especially useful when we need values that cover a wide range.
Syntax
Following is the syntax of the Numpy logspace() function −
numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)
Parameters
Following are the parameters of the Numpy logspace() function −
- start - starting exponent for the range (basestart).
- stop - ending exponent for the range (basestop).
- num - number of samples to generate. Default is 50.
- endpoint - If True, the stop value is included in the range otherwise, the stop value is excluded. Default is True.
- base - base of the logarithmic scale. Default is 10.0.
- dtype - It is the desired data type for the array.
Return Values
This function returns a numpy array of numbers spaced evenly on a log scale from basestart to basestop.
Example
Following is a basic example to generate a numpy array using Numpy logspace() −
import numpy as np logspace_array = np.logspace(0, 3, num=5) print("Logarithmic space array:\n", logspace_array)
Output
The output will show 5 values spaced on a logarithmic scale:
Logarithmic space array: [ 1. 5.62341325 31.6227766 177.827941 1000. ]
Example : Changing the base in 'logspace()'
In the numpy.logspace() function, the base parameter can take any positive number as its value. Commonly used bases include −
- Base 10 − Default base in numpy.logspace(), creating scales in powers of 10. For an example, (10^0), (10^1), (10^2), etc.
- Base 2 − This base is useful for binary or exponential growth patterns. For an example, (2^0), (2^1), (2^2), etc.
- Base e − Euler's number (approximately 2.718), useful in natural logarithmic scales, common in scientific applications (e.g., (e^0), (e^1), (e^2)).
- Custom Bases − It can be any positive real number can be used to suit specific requirements. For example, a base of 1.5 or 3 could be used to model finer or coarser exponential growth, respectively.
This range of values allows for great flexibility in generating logarithmic scales suited to diverse contexts and applications.
In this example, we use a base of 2 to create a logarithmic scale from (2^0) to (2^4) −
import numpy as np logspace_base2 = np.logspace(0, 4, num=5, base=2) print("Logarithmic space array with base 2:\n", logspace_base2)
Output
The output will display values spaced on a logarithmic scale with base 2:
Logarithmic space array with base 2: [ 1. 2. 4. 8. 16.]
Example : Specifying Data Type in 'logspace()'
The numpy.logspace() function allows us to generate a NumPy array of values evenly spaced on a logarithmic scale. Additionally, we can specify the data type of the output array using the dtype parameter, ensuring that the generated values match the desired precision, such as float or integer.
In the following example, we have generated a numpy array with integer values on the logarithmic scale value by setting the dtype parameter to int −
import numpy as np logspace_int = np.logspace(1, 3, num=4, dtype=int) print("Logarithmic space array with integer data type:\n", logspace_int)
Output
Following is the output of the above code −
Logarithmic space array with integer data type: [ 10 46 215 1000]
Example : Excluding Endpoint in 'logspace()'
The numpy.logspace() function provides an option to exclude the endpoint of the logarithmic sequence using the endpoint parameter. By default, endpoint=True, which means the final value in the specified range will be included. if endpoint=False is set, the final value will be excluded, which gives more control over the spacing of values. This can be useful when creating ranges for iterations or sampling.
In this example, we generate a sequence of values from (10^1) to (10^3) but exclude the endpoint (103) by setting endpoint=False −
import numpy as np logspace_no_endpoint = np.logspace(1, 3, num=4, endpoint=False) print("Logarithmic space array without endpoint:\n", logspace_no_endpoint)
Output
Following is the output of the above code −
Logarithmic space array without endpoint: [ 10. 31.6227766 100. 316.22776602]