Forums

NumPy.log

Hey everyone,

I'm trying to calculate the logarithm for each value of an array (numpy.ndarray):

>>> import numpy
>>> x = numpy.random.rand(M,N)
>>> x
array([[ 1, 2, 3],
       [ 4 , 5, 6],
       [ 7,  8, 9]])
>>> x.log
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'log'
>>>

Do you know any way to make numpy.log wor in that case?

Thanks a lot!

It's a general numpy question, not directly related with PythonAnywhere -- you may want to refer to numpy documentation or other forums. The simple answer is that you need to run log on a value, not an array of values, I suppose.