[Numpy-discussion] strange behavior of += with object array
Neal Becker
ndbecker2 at gmail.com
Thu Oct 31 19:22:32 EDT 2013
import numpy as np
#from accumulator import stat2nd_double
## Just to make this really clear, I'm making a dummy
## class here that overloads +=
class stat2nd_double (object):
def __iadd__ (self, x):
return self
m = np.empty ((2,3), dtype=object)
m[:,:] = stat2nd_double()
m[0,0] += 1.0 <<<< no error here
m += np.ones ((2,3)) <<< but this gives an error
Traceback (most recent call last):
File "test_stat.py", line 13, in <module>
m += np.ones ((2,3))
TypeError: unsupported operand type(s) for +: 'stat2nd_double' and 'float'
More information about the NumPy-Discussion
mailing list