pythonnumpy

Can't figure out why numpy.log10 outputs nan?


So I have an 500k array of floating values. When I am trying to:

np.log10(my_long_array)

270k numbers getting replaced to nan, and they are not that small. For example:

In [1]: import numpy as np

In [2]: t = -0.055488893531690543

In [3]: np.log10(t)
/home/aydar/anaconda3/bin/ipython:1: RuntimeWarning: invalid value encountered in log10
  #!/home/aydar/anaconda3/bin/python3
Out[3]: nan

In [4]: type(t)
Out[4]: float

What am I missing?


Solution

  • the logarithm of a negative number is undefined, hence the nan

    From the docs to numpy.log10:

    Returns: y : ndarray

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