How do you take the log base 10 of an array in python?

numpy.log10(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])=<ufunc 'log10'>#

Return the base 10 logarithm of the input array, element-wise.

Parametersxarray_like

Input values.

outndarray, None, or tuple of ndarray and None, optional

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. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.

wherearray_like, optional

This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

**kwargs

For other keyword-only arguments, see the ufunc docs.

Returnsyndarray

The logarithm to the base 10 of x, element-wise. NaNs are returned where x is negative. This is a scalar if x is a scalar.

Notes

Logarithm is a multivalued function: for each x there is an infinite number of z such that 10**z = x. The convention is to return the z whose imaginary part lies in [-pi, pi].

For real-valued input data types, log10 always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag.

For complex-valued input, log10 is a complex analytical function that has a branch cut [-inf, 0] and is continuous from above on it. log10 handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard.

References

1

M. Abramowitz and I.A. Stegun, “Handbook of Mathematical Functions”, 10th printing, 1964, pp. 67. https://personal.math.ubc.ca/~cbm/aands/page_67.htm

2

Wikipedia, “Logarithm”. https://en.wikipedia.org/wiki/Logarithm

Examples

>>> np.log10([1e-15, -3.])
array([-15.,  nan])

How do you take the log base 10 of an array in python?

Numpy is a third-party library for the Python language, adding support for large, multi-dimensional arrays and matrices, accompanied by many high-level mathematical functions to execute on these arrays.

The np.log10() is a mathematical library function used to get the natural logarithm of any object or an array with the base 10. The np.log10() function accepts two arguments and returns the array of natural logarithms of the given array elements where the base is 10.

Syntax

numpy.log10(array[, out] = ufunc ‘log10’)

Parameters

The log10() function can take up to two main arguments:

  1. array: This is the input array or the object whose log is calculated.
  2. out: This is an optional field. A position the result is stored in. If given, it must have a form to which the inputs convey. If not provided or None, it returns a freshly-allocated list. A tuple must have the same length as the number of outputs (possible only as a keyword argument).

Return Value

The log10() function returns an array of natural logarithms of the given array elements where the base is 10.

Numpy log10() Program implementation

See the following code.

# Program to show the working of numpy.log

# Importing numpy
import numpy as np

# We will create an 1D array
arr = np.array([4, 14, 10, 63, 11, 4, 64])
# Printing the array
print("The array is: ", arr)
# Shape of the array
print("Shape of the array is : ", np.shape(arr))

# Calculating natural log of value arr[i]+1
out = np.log10(arr)
print("Natural logarithm of the given array of base 10 is ")
print(out)

Output

The array is:  [ 4 14 10 63 11  4 64]
Shape of the array is :  (7,)
Natural logarithm of the given array of base 10 is
[0.60205999 1.14612804 1.         1.79934055 1.04139269 0.60205999
 1.80617997]

Explanation

In this program, we have first declared an array of shape 7, we have printed the array. Then we have called numpy.log10() to calculate the natural logarithm of the items of the given array.

Graphical representation of log10()

Let’s see the graphical representation of the log10() function.

# Program to show Graphical representation

# Importing numpy
import numpy as np
import matplotlib.pyplot as plt

# We will create an 1D array
arr = np.array([40, 2.4, 0.14, 63, 1.2, 1, 4])
# Printing the array
print("The array is: ", arr)
# Shape of the array
print("Shape of the array is : ", np.shape(arr))

# Calculating natural log of value arr[i]+1
out = np.log10(arr)
print("Natural logarithm of the given array of base 10 is ")
print(out)

# Ploting of original array in Graph
# Color will be in Green
plt.plot(arr, arr, color='green', marker='x')

# Ploting of natural log array in Graph
# Color will be in blue
plt.plot(out, arr, color='blue', marker='o')

# Showing the Graphical represntation
plt.title("numpy.log10()")
plt.xlabel("Natural Log Array")
plt.ylabel("Original Array")
plt.show()

Output

The array is:  [40.    2.4   0.14 63.    1.2   1.    4.  ]
Shape of the array is :  (7,)
Natural logarithm of the given array of base 10 is
[ 1.60205999  0.38021124 -0.85387196  1.79934055  0.07918125  0.
  0.60205999]

How do you take the log base 10 of an array in python?

Explanation

In this program, we have first declared an array of shape 7; we have printed the array where array elements are in float data type.

Then we have called numpy.log10() to calculate the natural logarithm of the elements of the given array.

After that, we have plotted the original array in a 2D graph which indicates using the Greenline.

Then we plotted the out array, which we got after finding the natural logarithm, which indicates using the blue line.

We can see the result in the above-given image.

Conclusion

Numpy log10() function helps the user calculate the Base-10 logarithm of x where x belongs to all the input array items.

That is it for the numpy log10() method.

See also

Numpy log()

Numpy log2()

Numpy log1p()

How do you find the log10 of a number in Python?

Description. The log10() method returns base-10 logarithm of x for x > 0..
Syntax. Following is the syntax for log10() method − import math math.log10( x ) ... .
Parameters. x − This is a numeric expression..
Return Value. This method returns the base-10 logarithm of x for x > 0..
Example. ... .
Output..

What does math log10 do in Python?

Python math. log10() function is a library method of the math module, and it is used to get the base-2 logarithm of the number; it accepts a number and returns the base-10 logarithm of the given number.

What is NP log10?

The np. log10() is a mathematical library function used to get the natural logarithm of any object or an array with the base 10. The np. log10() function accepts two arguments and returns the array of natural logarithms of the given array elements where the base is 10.

What is the base of log in Numpy?

Natural logarithm, element-wise. The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e .