how can I calc pow of fractions or nth root square in numpy?

marco picture marco · Oct 21, 2014 · Viewed 14.6k times · Source

I'm trying to calculate the 8th root square of a value or its ^1/8, but numpy is always returning the wrong value

temp = 141.18
h2 = temp ** (1/8)
h2_ = np.power(temp, (1/8))

my output is always 1.0 . I've tried square command too. I need to use numpy, I'm using other numpy arrays in mycode, just to keep compatible.

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Oct 21, 2014
>>> 1/8
0
>>> 1./8
0.125

And of course, anything to the power of 0 results in 1.