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:
- x: input array
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 packages import numpy as np # Creating an array array = np.array([ 10 , 20 , 30 ]) print (array) # shape of the array is print ( "Shape of the array is : " ,array.shape) # dimension of the array print ( "The dimension of the array is : " ,array.ndim) # Datatype of the array print ( "Datatype of our Array is : " ,array.dtype) # computing log10 for the given array 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 # computing log10 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