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

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?



Read more here: https://stackoverflow.com/questions/64948128/find-the-maximum-value-in-the-numpy-list-while-ignoring-infinite-values

Content Attribution

This content was originally published by Elhanan Schwarts at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: