
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return Evenly Spaced Numbers Over a Log Scale in NumPy
To return evenly spaced numbers on a log scale, use the numpy.logspace() method in Python Numpy. The 1st parameter is the "start" i.e. the start of the sequence. The 2nd parameter is the "end" i.e. the end of the sequence.
In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below). The start is the base ** start is the starting value of the sequence. The stop is the base ** stop is the final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last are returned. The base of the log space. The step size between the elements in ln(samples) / ln(base) (or log_base(samples)) is uniform. Default is 10.0.
The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.
Steps
At first, import the required library −
import numpy as np
Return evenly spaced numbers on a log scale using the numpy.logspace() method in Python Numpy. The 3rd parameter is the num is the number of samples to generate. Default is 50 −
arr = np.logspace(35.0, 70.0) print("Array...
", arr)
Get the type −
print("
Type...
", arr.dtype)
Get the dimensions −
print("
Dimensions...
",arr.ndim)
Get the shape −
print("
Shape...
",arr.shape)
Get the number of elements −
print("
Number of elements...
",arr.size)
Example
import numpy as np # To return evenly spaced numbers on a log scale, use the numpy.logspace() method in Python Numpy # The 1st parameter is the "start" i.e. the start of the sequence # The 2nd parameter is the "end" i.e. the end of the sequence # The 3rd parameter is the num i.s the number of samples to generate. Default is 50. arr = np.logspace(35.0, 70.0) print("Array...
", arr) # Get the type print("
Type...
", arr.dtype) # Get the dimensions print("
Dimensions...
",arr.ndim) # Get the shape print("
Shape...
",arr.shape) # Get the number of elements print("
Number of elements...
",arr.size)
Output
Array... [1.00000000e+35 5.17947468e+35 2.68269580e+36 1.38949549e+37 7.19685673e+37 3.72759372e+38 1.93069773e+39 1.00000000e+40 5.17947468e+40 2.68269580e+41 1.38949549e+42 7.19685673e+42 3.72759372e+43 1.93069773e+44 1.00000000e+45 5.17947468e+45 2.68269580e+46 1.38949549e+47 7.19685673e+47 3.72759372e+48 1.93069773e+49 1.00000000e+50 5.17947468e+50 2.68269580e+51 1.38949549e+52 7.19685673e+52 3.72759372e+53 1.93069773e+54 1.00000000e+55 5.17947468e+55 2.68269580e+56 1.38949549e+57 7.19685673e+57 3.72759372e+58 1.93069773e+59 1.00000000e+60 5.17947468e+60 2.68269580e+61 1.38949549e+62 7.19685673e+62 3.72759372e+63 1.93069773e+64 1.00000000e+65 5.17947468e+65 2.68269580e+66 1.38949549e+67 7.19685673e+67 3.72759372e+68 1.93069773e+69 1.00000000e+70] Type... float64 Dimensions... 1 Shape... (50,) Number of elements... 50