Skip to main content
added 743 characters in body
Source Link
mins
  • 267
  • 1
  • 10

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 to log10. The reason is when numpy.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. So log10 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

There is an option where in log10 for that:

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 order to give a value for the unprocessed elements, you need to use numpy.where as you did.

So you can adjust your code this way:

HHdB = numpy.where(HHPow>0, 10 * numpy.log10(HHPow, where=HHPow>0), numpy.nan)

More: log10 documentation.

Adjust your code this way:

HHdB = numpy.where(HHPow>0,
                   10 * numpy.log10(HHPow, where=HHPow>0),
                   0)

Option where in log10 is 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 to log10. The reason is when numpy.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. So log10 is computed for all elements and the warning is issued.

Instead of a default 0, you could also use numpy.nan, which is processed correctly by pyplot.

More: log10 documentation and where documentation

added 130 characters in body
Source Link
mins
  • 267
  • 1
  • 10

There is an option where in log10 for that:

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 order to give a value for the unprocessed elements, you need to use numpy.where as you did.

So you can adjust your code this way:

HHdB = numpy.where(HHPow>0, 10 * numpy.log10(HHPow, where=HHPow>0), numpy.nan)

More: log10 documentation.

There is an option where in log10 for that:

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.

So you can adjust your code this way:

HHdB = 10 * numpy.log10(HHPow, where=HHPow>0)

More: log10 documentation.

There is an option where in log10 for that:

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 order to give a value for the unprocessed elements, you need to use numpy.where as you did.

So you can adjust your code this way:

HHdB = numpy.where(HHPow>0, 10 * numpy.log10(HHPow, where=HHPow>0), numpy.nan)

More: log10 documentation.

Source Link
mins
  • 267
  • 1
  • 10

There is an option where in log10 for that:

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.

So you can adjust your code this way:

HHdB = 10 * numpy.log10(HHPow, where=HHPow>0)

More: log10 documentation.