There is an optionAdjust your code this way:
HHdB = numpy.where(HHPow>0,
10 * numpy.log10(HHPow, where=HHPow>0),
0)
Option where
in log10
for thatis used to prevent such warning or other errors:
where: array_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.
For instance if the condition is HHPow>0
, the log is calculated when it is True
for the element, else the element is not processed.
In case the output array is created by Numpy, like here, the returned value for non-processed elements is undetermined, in my case this is -inf
. In order to give a default value for the unprocessed elements, you need to use numpy.where
as you did.
- Note you still need to provide the
where
parameter tolog10
. The reason is whennumpy.where
is used, it picks the values from one of the two arrays provided. But the arrays are not computed on the fly, they are completely computed upfront. Solog10
is computed for all elements and the warning is issued.
SoInstead of a default 0, you can adjust your code this way:could also use numpy.nan
, which is processed correctly by pyplot
.
HHdB = numpy.where(HHPow>0, 10 * numpy.log10(HHPow, where=HHPow>0), numpy.nan)
More: log10 documentation. and where documentation