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

Dave Hirschfeld dave.hirschfeld@gmail....
Fri Aug 10 04:36:48 CDT 2012


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
> This works correctly when a and b are real arrays:
> a = ones(1)
> b = ones(1)
> a[0] = b
> Bug or feature?
> Thanks,
> Mark
> 

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:


In [15]: sys.version
Out[15]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'

In [16]: sys.version
Out[16]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'

In [17]: np.__version__
Out[17]: '1.6.2'

In [18]: a = ones(1,'D')

In [19]: b = 2*ones(1,'D')

In [20]: a[0] = b
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-0c4fc6d780e3> in <module>()
----> 1 a[0] = b

TypeError: can't convert complex to float

In [21]: a[0:1] = b

In [22]: 

-Dave



More information about the NumPy-Discussion mailing list