Compute the logarithm base 10 with NumPy-scimath in Python
The NumPy package provides us with numpy.lib.scimath.log10 to Compute the logarithm base 10 with scimath in Python. Let’s go through the syntax as per the following to understand the method much better.
Syntax: lib.scimath.log10(x)
Returns the “primary value” of (see numpy.log10). This is a real number if real x > 0 (log10(0) = -inf, log10(np.inf) = inf). The complicated principle value is returned if none of the above conditions are met.
Parameters:
Returns:
array or scalar. if x is scalar , a scalar is returned. if x is array, a computed array is returned.
Example 1:
The NumPy package is imported. we create an array and find its shape, dimensions, and dtype with the .shape, .ndim and .dtype attributes. lib.scimath.log10() method is used to find the logarithm base 10.
Python3
import numpy as np
array = np.array([ 10 , 20 , 30 ])
print (array)
print ( "Shape of the array is : " ,array.shape)
print ( "The dimension of the array is : " ,array.ndim)
print ( "Datatype of our Array is : " ,array.dtype)
print (np.lib.scimath.log10(array))
|
Output:
[10 20 30]
Shape of the array is : (3,)
The dimension of the array is : 1
Datatype of our Array is : int64
[1. 1.30103 1.47712125]
Example 2:
As described np.lib.scimath.log10() returns infinity when np.inf is passed, -inf is returned when 0 is passed, and when -inf is passed inf is returned.
Python3
import numpy as np
print (np.lib.scimath.log10(np.inf))
print (np.lib.scimath.log10( - np.inf))
print (np.lib.scimath.log10( 0 ))
|
Output:
inf
(inf+1.3643763538418412j)
-inf
Last Updated :
25 Apr, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...