Sometimes, we want to do exponential and logarithmic curve fitting in Python.
In this article, we’ll look at how to do exponential and logarithmic curve fitting in Python.
How to do exponential and logarithmic curve fitting in Python?
To do exponential and logarithmic curve fitting in Python, we fit y
against log x
.
For instance, we write
x = numpy.array([1, 7, 20, 50, 79])
y = numpy.array([10, 19, 30, 35, 51])
numpy.polyfit(numpy.log(x), y, 1)
to call numpy.array
to create NumPy arrays of x and y axis values.
Then we call numpy.polyfit
with numpy.log(x)
, which is an array with the log of each value in x
, y
, and 1 to do logarithmic curve fitting.
Conclusion
To do exponential and logarithmic curve fitting in Python, we fit y
against log x
.