Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take the log of all elements of a list

Tags:

python

arrays

I have an array

x = [1500, 1049.8, 34, 351, etc] 

How can I take log_10() of the entire array?

like image 678
Dax Feliz Avatar asked Jul 25 '12 19:07

Dax Feliz


People also ask

Can you take log of array in Python?

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.

How do you take the natural log of a list in Python?

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.

How do I see all elements in a list?

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.


1 Answers

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.

like image 158
jmetz Avatar answered Sep 30 '22 19:09

jmetz