I have an array
x = [1500, 1049.8, 34, 351, etc]
How can I take log_10() of the entire array?
Python's numpy. log() is a mathematical function that computes the natural logarithm of an input array's elements. The natural logarithm is the inverse of the exponential function, such that log (exp(x)) = x.
log() in Python. The numpy. log() is a mathematical function that helps user to calculate Natural logarithm of x where x belongs to all the input array elements. Natural logarithm log is the inverse of the exp(), so that log(exp(x)) = x.
Using Count() The python list method count() returns count of how many times an element occurs in list. So if we have the same element repeated in the list then the length of the list using len() will be same as the number of times the element is present in the list using the count(). The below program uses this logic.
numpy will do that for you.
import numpy numpy.log10(mat)
Note
mat
does not have to be a numpy array for this to work, and numpy
should be faster than using a list comprehension as other answers suggest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With