To compute the logarithm base 10 with scimath, use the scimath.log10() method in Python Numpy. The method returns the log base 10 of the x value(s). If x was a scalar, so is out, otherwise an array object is returned.
For a log10() that returns NAN when real x < 0, use numpy.log10 (note, however, that otherwise numpy.log10 and this log10 are identical, i.e., both return -inf for x = 0, inf for x = inf, and, notably, the complex principle value if x.imag != 0). The 1st parameter, x is the value(s) whose log base 10 is (are) required.
Steps
At first, import the required libraries −
import numpy as np
Creating a numpy array using the array() method −
arr = np.array([10**1, -10**1, -10**2, 10**2, -10**3, 10**3])
Display the array −
print("Our Array...\n",arr)
Check the Dimensions −
print("\nDimensions of our Array...\n",arr.ndim)
Get the Datatype −
print("\nDatatype of our Array object...\n",arr.dtype)
Get the Shape −
print("\nShape of our Array object...\n",arr.shape)
To compute the logarithm base 10 with scimath, use the scimath.log10() method −
print("\nResult (log10)...\n",np.emath.log10(arr))
Example
import numpy as np # Creating a numpy array using the array() method arr = np.array([10**1, -10**1, -10**2, 10**2, -10**3, 10**3]) # Display the array print("Our Array...\n",arr) # Check the Dimensions print("\nDimensions of our Array...\n",arr.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",arr.dtype) # Get the Shape print("\nShape of our Array object...\n",arr.shape) # To compute the logarithm base 10 with scimath, use the scimath.log10() method in Python Numpy print("\nResult (log10)...\n",np.emath.log10(arr))
Output
Our Array... [ 10 -10 -100 100 -1000 1000] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (6,) Result (log10)... [1.+0.j 1.+1.36437635j 2.+1.36437635j 2.+0.j 3.+1.36437635j 3.+0.j ]