Issue
I would like to generate a logarithmic curve between two values, with a set number of datapoints in between.
I tried np.logspace(start,end,num_points)
but that has an issue:
The created values are much higher than I expected (I believe this is due to the base value?)
How can I create values to be in the input range (with the distance between them being logarithmic)? i.e.
start=10; end=12; num_points=6
output: array([10, 11, 11.5, 11.75, 11,9, 12])
(the numbers in the output are just my estimation, real values will be different).
My end goal is to plot these values (y-axis) against the num_points (as x-axis).
plt.plot(num_point,output)
Solution
You can log a linspace
with start and end points raised correspondingly:
import numpy as np
import matplotlib.pyplot as plt
plt.plot(range(6), [10, 11, 11.5, 11.75, 11.9, 12], 'ko-', label='requested')
plt.plot(range(6), np.log10(np.linspace(10**10, 10**12, 6)), 'ro-', label='log10')
plt.plot(range(6), np.log(np.linspace(np.exp(10), np.exp(12), 6)), 'bo-', label='log')
plt.legend()
Answered By - Stef
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.