BetterDocs
Home
Docs

Creation | np.logspace()

Method:

np.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=np.float64, axis=0)

Generates numbers spaced evenly on a log scale.

Returns:

np.ndarray

Parameters:

start: int-

Starting value of the NumPy array.

import numpy as np
arr = np.logspace(start=0, stop=2, num=5, base=10.0)
# Both 'start' & 'stop' are included as endpoint=True
print(arr)
'''
Output:
[  1.           3.16227766  10.          31.6227766  100.        ]
'''

Firstly the values are converted into np.linspace()  and the base value is raised to the power of the returned linspace values.

The values in the above array are - [10.00.0, 10.00.5, 10.01.0, 10.01.5, 10.02.0]

stop: int-

End of the interval value of the NumPy array.

import numpy as np
arr = np.logspace(start=0, stop=1, num=5)
# Both 'start' & 'stop' are included as endpoint=True
print(arr)
'''
Output:
[ 1.          1.77827941  3.16227766  5.62341325 10.        ]
'''

If stop > start, an array is returned with data in decreasing order.

If stop < start, an array is returned with data in ascending order.

If stop = start, an array of basestart is returned.

num: int-

Number of the intervals in the NumPy array.

import numpy as np
arr = np.logspace(start=1, stop=2, num=10)
# Both 'start' & 'stop' are included as endpoint=True
print(arr)
'''
Output:
[ 10.          12.91549665  16.68100537  21.5443469   27.82559402
  35.93813664  46.41588834  59.94842503  77.42636827 100.        ]
'''

endpoint: (True or False) Optional-

If endpoint is set to True, stop value is included in the returned NumPy array.

endpoint = True (default) +

endpoint = False +

base: (int or float)-

The base of the logarithmic scale.

import numpy as np
arr = np.logspace(start=0, stop=1, num=5, base=5)
# Both 'start' & 'stop' are included
print(arr)
'''
Output:
[1.         1.49534878 2.23606798 3.34370152 5.        ]
'''

dtype: np.float64, Optional-

The desired data-type for the NumPy array is inferred from the dtype specified.

import numpy as np
arr = np.logspace(start=0, stop=4, num=5, dtype=np.int32)
# Both 'start' & 'stop' are included
print(arr)
'''
Output:
[    1    10   100  1000 10000]
'''

Values: +

By passing the dtype, you are implicitly converting the values to the passed dtype.

axis: int Optional-

The axis in the result to store the samples. Relevant only if start or stop are array-like.

axis = 0 (default) +

axis = -1 +

axis is only useful when dealing with array-like input.

Plays a vital role in transformation of the input along your axis (columns or rows).


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy