[Numpy-discussion] Second try: possible bug in assignment to complex array

Fabrice Silva silva@lma.cnrs-mrs...
Fri Aug 10 04:44:21 CDT 2012


Le vendredi 10 août 2012, Dave Hirschfeld a écrit :
> Mark Bakker <markbak <at> gmail.com> writes:
> > I think there is a problem with assigning a 1D complex array of length one
> > to a position in another complex array.
> > Example:
> > a = ones(1,'D')
> > b = ones(1,'D')
> > a[0] = b
> > ---------------------------------------------------------------------------
> > TypeError                                 Traceback (most recent call last)
> > <ipython-input-37-0c4fc6d780e3> in <module>()
> > ----> 1 a[0] = b
> > TypeError: can't convert complex to float
> > 
> 
> I can't help unfortunately, but I can confirm that I also see the problem
> on Win32 Python 2.7.3, numpy 1.6.2.
> As a workaround it appears that slicing works:

Same on debian (unstable), Python 2.7, numpy 1.6.2
In [5]: a[0] = b
TypeError: can't convert complex to float
In [6]: a[0] = b[0]

Other workarounds : asscalar and squeeze
In [7]: a[0] = np.asscalar(b)
In [8]: a[0] = b.squeeze()


-- 
Fabrice Silva



More information about the NumPy-Discussion mailing list