The logspace() method creates an array with evenly spaced numbers on a log scale.
logspace() Syntax
The syntax of logspace() is:
numpy.logspace(start, stop, num = 50, endpoint = True, base = 10, dtype = None, axis = 0)
logspace() Argument
The logspace() method takes the following arguments:
start- the start value of the sequencestop- the end value of the sequencenum(optional)- number of samples to generateendpoint(optional)- specifies whether to include end valuedtype(optional)- type of output arraybase(optional)- base of log scaleaxis(optional)- the axis in the result to store the samples
>Notes:
- In linear space, the sequence generated by
logspace()starts at base ** start (base to the power of start) and ends with base ** stop. - If
dtypeis omitted,logspace()will determine the type of the array elements from the types of other parameters.
logspace() Return Value
The logspace() method returns an array of evenly spaced values on a logarithmic scale.
Example 1: Create a 1-D Array Using logspace
Output
Array1: [ 100. 177.827941 316.22776602 562.34132519 1000. ] Array2: [100. 158.48931925 251.18864315 398.10717055 630.95734448] Array3: [4. 4.75682846 5.65685425 6.72717132 8. ]
Example 2: Create an N-d Array Using logspace
Similar to 1D arrays, we can also create N-d arrays using logspace. For this, we can simply pass a sequence to start and stop values instead of integers.
Let us see an example.
Output
Array1: [[1.e+01 1.e+02] [1.e+02 1.e+03] [1.e+03 1.e+04] [1.e+04 1.e+05] [1.e+05 1.e+06]] Array2: [[1.e+01 1.e+02 1.e+03 1.e+04 1.e+05] [1.e+02 1.e+03 1.e+04 1.e+05 1.e+06]]