Skip to content

BUG: invalid value encountered in power resulting in NaNs #20186

@jecampagne

Description

@jecampagne

Describe the issue:

NaN values in exponentiation of y as np.array either y**val or np.power(y,val) depending on val values but strange. I'm using fresh version from conda install 1.21.2. May be someone can tell me if he/she reproduces the problem

Reproduce the code example:

import numpy as np
y = np.array([-8.18254833e-09, -9.87463911e-09, -1.19166418e-08, -1.43809156e-08,
 -1.73547831e-08, -2.09436246e-08, -2.52746120e-08, -3.05012158e-08,
 -3.68086427e-08, -4.44203992e-08, -5.36062108e-08, -6.46915807e-08,
 -7.80693235e-08, -9.42134850e-08, -1.13696140e-07, -1.37207665e-07,
 -1.65581201e-07, -1.99822175e-07, -2.41143930e-07, -2.91010720e-07,
 -3.51189595e-07, -4.23813019e-07, -5.11454432e-07, -6.17219445e-07,
 -7.44855884e-07, -8.98886599e-07, -1.08476973e-06, -1.30909213e-06,
 -1.57980275e-06, -1.90649433e-06, -2.30074333e-06, -2.77652011e-06,
 -3.35068404e-06, -4.04358084e-06, -4.87976360e-06, -5.88886280e-06,
 -7.10663629e-06, -8.57623638e-06, -1.03497389e-05, -1.24899888e-05,
 -1.50728266e-05, -1.81897762e-05, -2.19512880e-05, -2.64906528e-05,
 -3.19687249e-05, -3.85796219e-05, -4.65576038e-05, -5.61853736e-05,
 -6.78040954e-05, -8.18254833e-05])

y**4.0  # np.power(y,4.0)  gives correct values
y**3.0000000000000001   # gives correct values
y**3.000000000000001 # leeds to Nan

array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

Error message:

RuntimeWarning: invalid value encountered in power
  y**3.000000000000001

NumPy/Python version information:

1.21.2 3.8.12 (default, Oct 12 2021, 13:49:34)
[GCC 7.5.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions