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

Paul Ray Paul.Ray at nrl.navy.mil
Sun Jan 15 08:50:28 CST 2006


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
exceptions.TypeError                                 Traceback (most  
recent call last)


TypeError: attribute 'real' of 'generic_arrtype' objects is not writable

In [11]: a = c[0]

In [12]: a?
Type:           complex64_arrtype
Base Class:     <type 'complex64_arrtype'>
String Form:    0j
Namespace:      Interactive

Thanks for any help,

-- Paul

Dr. Paul S. Ray              E-mail: Paul.Ray at nrl.navy.mil
Naval Research Laboratory    WWW   : http://xweb.nrl.navy.mil/ 
Code 7655                    Phone : (202) 404-1619
Washington, DC 20375         AIM   : NRLPSR

More information about the SciPy-user mailing list