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

Paul Ray Paul.Ray at nrl.navy.mil
Sun Jan 15 20:45:04 CST 2006

On Jan 15, 2006, at 6:01 PM, Travis Oliphant wrote:

> 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.


Thanks for the quick answer.  That does indeed fix the problem.

It is a very strange syntax, however.  Is there some reason why the  
real part of a scalar can't be set with that syntax (c[0].real = 2.3)?

Is there any big inefficiency with c.real[0]?  It seems like  
converting a whole array to real, then grabbing the 0th element,  
which is counter-intuitive for an operation where I want to grab the  
0th element and set its real part to some number.


-- 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