Find the maximum value in the numpy list while ignoring infinite values

  numpy, python

I have the following code:

import numpy as np
from numpy import ma

e = np.array([1, 0.2, 0, 0.3, 0, 0.4, 0])
e = ma.log10(e)
result = np.nanargmax(np.where(e != 0, e, np.nan))

I try to find the highest value in the list after logging (Ignoring 0 values). Since there are zeros in the original list, the result obtained after the log operation for the zeros should be ignored as well.

In the example above the expected result should index 5. bu the actual result is index 2.

What needs to change to achieve the desired result?

Source: Python Questions

LEAVE A COMMENT