[Numpy-discussion] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

Sebastian Walter sebastian.walter@gmail....
Sun Jun 7 05:09:40 CDT 2009


Apparently the bugfix has been undone in the current bleeding edge
version of numpy:


----------------------- numpy_float64_issue.py
----------------------------------
from numpy import *
import numpy
print 'numpy.__version__=',numpy.__version__

class adouble:
       def __init__(self,x):
               self.x = x
       def __mul__(self,rhs):
               if isinstance(rhs,adouble):
                       return adouble(self.x * rhs.x)
               else:
                       return adouble(self.x * rhs)
       def __str__(self):
               return str(self.x)

x = adouble(3.)
y = adouble(2.)
u = array([adouble(3.), adouble(5.)])
v = array([adouble(2.), adouble(7.)])
z = array([2.,3.])

print x * y              # ok
print u * v              # ok
print u * z              # ok
print u * 3.             # ok
print u * z[0]           # _NOT_ OK!
print u * float64(3.)    # _NOT_ OK!

---------------- end  numpy_float64_issue.py  --------------------------

OUTPUT:

basti@shlp:~/tmp$ python numpy_float64_issue.py
numpy.__version__= 1.4.0.dev7039
6.0
[6.0 35.0]
[6.0 15.0]
[9.0 15.0]
Traceback (most recent call last):
  File "numpy_float64_issue.py", line 26, in <module>
    print u * z[0]           # _NOT_ OK!
TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and
'numpy.float64'


Should I open a ticket for that?

Sebastian

On Tue, Jun 2, 2009 at 4:18 PM, Darren Dale<dsdale24@gmail.com> wrote:
>
>
> On Tue, Jun 2, 2009 at 10:09 AM, Keith Goodman <kwgoodman@gmail.com> wrote:
>>
>> On Tue, Jun 2, 2009 at 1:42 AM, Sebastian Walter
>> <sebastian.walter@gmail.com> wrote:
>> > Hello,
>> > Multiplying a Python float to a numpy.array of objects works flawlessly
>> > but not with a numpy.float64 .
>> > I tried  numpy version '1.0.4' on a 32 bit Linux and  '1.2.1' on a 64
>> > bit Linux: both raise the same exception.
>> >
>> > Is this a (known) bug?
>
> Yes, it was fixed in numpy-1.3.
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


More information about the Numpy-discussion mailing list