[Numpy-discussion] Pow() with negative exponent

Ivan Vilata i Balaguer ivilata at carabos.com
Mon May 22 23:50:03 EDT 2006


(I'm sending this again because I'm afraid the previous post may have
qualified as spam because of it subject.  Sorry for the inconvenience.)

Hi all, when working with numexpr, I have come across a curiosity in
both numarray and numpy::

  In [30]:b = numpy.array([1,2,3,4])
  In [31]:b ** -1
  Out[31]:array([1, 0, 0, 0])
  In [32]:4 ** -1
  Out[32]:0.25
  In [33]:

According to http://docs.python.org/ref/power.html:

  For int and long int operands, the result has the same type as the
  operands (after coercion) unless the second argument is negative; in
  that case, all arguments are converted to float and a float result is
  delivered.

Then, shouldn’t be ``b ** -1 == array([1.0, 0.5, 0.33333333, 0.25])``
(i.e. a floating point result)? Is this behaviour intentional?  (I
googled for previous messages on the topic but I didn’t find any.)

Thanks,

::

	Ivan Vilata i Balaguer   >qo<   http://www.carabos.com/
	       Cárabos Coop. V.  V  V   Enjoy Data
	                          ""

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 307 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060522/bc3342e5/attachment.sig>


More information about the NumPy-Discussion mailing list