1

I have written this function in python:

def F(x):
    if e==0: 
        F = np.exp(-s*x)
    else:
        F = np.amax((1-(e*x))**(s/e))
    return F

X is a array, e and s are parameter values.

The function works fine when testing it with regular numbers, but when using it later on to make indices, I get this error.

/var/folders/ms/77r_86797xng4439fph6sg9h0000gn/T/ipykernel_19925/2944436554.py:6: RuntimeWarning: invalid value encountered in power
  F = np.amax((1-(e*x))**(s/e))

Any suggestions?

Nina
  • 23
  • 3
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – bn_ln Nov 19 '22 at 11:20
  • What's the value range (min, max, min(abs())) of each variable? – Homer512 Nov 19 '22 at 11:36
  • 2
    What are `e` and `s`? Global? are you passing it in? etc.? They are undefined in the example you provided. So, give some examples of how this is actually used and what the values of the variables are – Aero Engy Nov 19 '22 at 11:51
  • 1
    The problem in the title of the question seems unrelated to the warning message that you encountered. Please clarify the actual problem, and please include enough additional code so that the question is a [mcve]. – John Coleman Nov 19 '22 at 12:54
  • 2
    You'll get the warning *RuntimeWarning: invalid value encountered in power* if there are any negative values in `1 - (e*x)` and `s/e` is not an integer. – Warren Weckesser Nov 19 '22 at 13:36

0 Answers0