I always use from __future__ import division
to avoid integer division problems. I just came across a case where it apparently still persists:
np.array([10])**(-1)
returns array([0])
, contrary to 1/np.array([10])
, which returns array([ 0.1])
as expected.
I know this can be fixed, e.g. by using np.array([10])**(-1.)
or converting the array to floats using astype('float')
. I would just like to know why it behaves like this, since it seems slightly inconsistent to me given that e.g. 10**(-1)
gives 0.1.