+4 votes
in Programming Languages by (60.2k points)

I am trying the following power operation, but I get the wrong answer. How can I fix it?

>>> np.power(100,50)

0

1 Answer

+2 votes
by (355k points)
selected by
 
Best answer

By default, the power() function uses 64-bit integer dtype. It is too small for such a big number. You need to use float64 dtype that offers a larger but inexact, range of possible values.

Here is the fix:

>>> np.power(100,50, dtype=np.float64)
1e+100


...