Exemples de comment calculer le logarithme naturel (népérien) avec python
Calculer le logarithme népérien avec le module math
Avec le module math:
>>> import math>>> math.e2.718281828459045>>> e = math.e>>> math.log(e)1.0
Calculer le logarithme népérien avec numpy
Avec numpy:
>>> import numpy as np>>> a = np.array([e,1,10,e**2])>>> np.log(a)array([ 1. , 0. , 2.30258509, 2. ])
Tracer la fonction logarithme népérien avec matplotlib

import matplotlib.pyplot as pltimport numpy as npdef function(x):return np.log(x)x = np.arange(0.01,10,0.1)y = function(x)plt.plot(x,y)plt.grid()plt.xlim(0,10)plt.title('How to calculate the Natural logarithm in python ?',fontsize=10)plt.xlabel('x',fontsize=8)plt.ylabel('log',fontsize=8)plt.savefig('how_to_caclulate_natural_logarithm_in_python.png', bbox_inches='tight')#plt.show()plt.close()
Calculer le logarithme en base 10
>>> math.log10(10)1.0>>> math.log10(100)2.0>>> math.log10(1000)3.0
Références
| Liens | Site |
|---|---|
| Logarithme naturel | wikipedia |
| python numpy ln | stackoverflow |
| math log | docs.python |
| numpy log | docs.scipy |
