[SciPy-user] Setting the real part of a complex array element

Travis Oliphant oliphant.travis at ieee.org
Sun Jan 15 17:01:08 CST 2006

Paul Ray wrote:

>I have some old code that tries to write to the real part of a  
>complex array element, but the syntax now seems to fail in the new  
>NumPy.  Looking in the new NumPy book (section 3.1.3) , it appears  
>that the .real attribute should be writable, but it does not seem to  
>work.  Does anyone know how to do this?
>In [1]: import numpy
>In [2]: numpy.__version__
>Out[2]: '0.9.2'
>In [4]: c = numpy.zeros(10,dtype=numpy.complex64)
>In [5]: c[0].real = 1.0

c.real[0] = 1.0

The problem is that

c[0] is not an array it is a scalar.    This would not have worked with 
typecode='D' with Numeric either...

c.real[0] = 1.0 will work.


More information about the SciPy-user mailing list