VOOZH about

URL: https://www.geeksforgeeks.org/python/compute-the-logarithm-base-10-with-numpy-scimath-in-python/

⇱ Compute the logarithm base 10 with NumPy-scimath in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Compute the logarithm base 10 with NumPy-scimath in Python

Last Updated : 25 Apr, 2022

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. 

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. 

Output:

inf
(inf+1.3643763538418412j)
-inf
Comment