2

I've found something peculiar regarding the power function from numpy which is inconsistent with what I thought was the general python-type-handling philosophy.

I had assumed that the output of numpy.power(x1, x2) is numerically equal to x1**x2, however this turns out not to be the case in case x2 < 0. As shown below:

In [320]: 2**-8
Out[320]: 0.00390625

In [321]: np.power(2, -8)
Out[321]: 0

In [322]: np.power(2., -8)
Out[322]: 0.00390625

While the philosophy is taught to be that the python interpreter changes type when necessary (e.g., 1/3 = 0.333, instead of 0), the numpy.power function appears to have escaped this philosophical change...

Or is there a reason why this is done the way it is done...???

kind regards

Joris
  • 168
  • 9
  • 1
    What's your NumPy version? On `1.12.1` the second one raises Value error. – Divakar Apr 04 '17 at 11:49
  • ah check.. I've got 1.11.1.... I'll update it, I prefer obviously the exception over an unexpected answer. thanks – Joris Apr 04 '17 at 11:51
  • Every base numpy integer type has a maximum size, and an array of them won't change dtype to grow when an value goes out of bounds. numpy has different goals in mind. – DSM Apr 04 '17 at 12:02

0 Answers0