How to compute natural, base 10, and base 2 logarithm for all elements in a given array using NumPy?
numpy.log( ) function in Python returns natural logarithmic of the input where the natural logarithm of a number is its logarithm to the base of the mathematical constant e, where e is an irrational and transcendental number approximately equal to 2.718281828459.
arr : Input Value. Can be scalar and numpy ndim array as well.
out : A location into which the result is stored. If provided, it must have a shape that the
inputs broadcast to. If not provided or None, a freshly-allocated array is returned.
shape must be same as input array.
If a scalar is provided to the function as input then the function is applied on the scalar and a scalar is returned.
Example: if 3 was given as input then log(3) will be returned as output.
natural logarithm of 3 is 1.0986122886681098 natural logarithm of 5 is 1.6094379124341003
If input is an n-dim array then function is applied element-wise. ex- np.log([1,2,3]) is equivalent to [np.log(1),np.log(2),np.log(3)]
[1.79175947 0.69314718 1.09861229 1.38629436 1.60943791]
Functions similar to numpy.log() :
- numpy.log2(): To calculate base 2 logarithms. Parameters of this functions are same as numpy.log(). It is also called the binary logarithm. Base 2 logarithm of y is the power to which the number 2 must be raised to obtain the value y.
- numpy.log10(): To calculate base 10 logarithms. Parameters are the same as numpy.log(). Base 10 logarithm of y is the power to which the number 10 must be raised to obtain the value y.
natural logarithm - [1.79175947 0.69314718 1.09861229 1.38629436 1.60943791] Base 2 logarithm - [2.5849625 1. 1.5849625 2. 2.32192809] Base 10 logarithm - [0.77815125 0.30103 0.47712125 0.60205999 0.69897 ]
Please Login to comment...