02 Apr Numpy Logs
Python Numpy has some predefined functions to work with Logs, such as numpy.log2(), numpy.log10(), etc. Let us see some examples:
Log Base 2
We will find the log base 2 using the numpy.log2() method. Let us see an example:
import numpy as np
# Create a Numpy array
n = np.array([1, 2, 3, 4, 5])
print("Array\n",n)
# log2
print("\nResult\n",np.log2(n))
Output
Array [1 2 3 4 5] Result [0. 1. 1.5849625 2. 2.32192809]
Log Base 10
We will find the log base 10 using the numpy.log10() method. Let us see an example:
import numpy as np
# Create an array
n = np.array([1, 2, 3, 4, 5])
print("Array\n",n)
# log10
print("\nResult\n",np.log10(n))
Output
Array [1 2 3 4 5] Result [0. 0.30103 0.47712125 0.60205999 0.69897 ]
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
No Comments