[SciPy-user] Real Array Expressed as Complex Array

Lorenzo Isella lorenzo.isella@gmail....
Thu Jul 3 15:27:22 CDT 2008

> 814v3268b9e5rca34b98bb7b84b57@mail.gmail.com> Content-Type: 
> text/plain; charset=ISO-8859-1 On Thu, Jul 3, 2008 at 9:39 AM, Lorenzo 
> Isella <lorenzo.isella@gmail.com> wrote:
>> > Dear All,
>> > I am bit puzzled: I was plotting a (rather complicated) analytical
>> > potential for which an analytical form is available.
>> > When asking to print out the value of the potential at the cut-off:
>> >
>> > print "at the cut-off, the dimensionless potential takes the value, ",
>> > pot_ext_dimensionless[-1]
>> >
>> > I got the following:
>> >
>> > at the cut-off, the dimensionless potential takes the value,
>> > (-6.48829965957e-06+0j)
>> >
>> > Now, since the potential I am coding via a function has to be a real
>> > function, I checked that the real part was always zero (as it should).
> I think you mean "...the *imaginary* part was always zero..."
Absolutely, a slip of the tongue.

>> > Since the result was that the array pot_ext_dimensionless is real, how
>> > comes that it is expressed as a complex array (though the imaginary
>> > part is always zero)?
> It all depends on how you're calculating the pot_ext_dimensionless
> array; clearly somewhere in there an operation makes it complex.
> You'll have to show us how it's calculated.
I think I solved the problem: I introduced some real elements taken from 
an array that has also some complex entries into pot_ext_dimensionless; 
although all the elements of pot_ext_dimensionless are all real, somehow 
scipy retains memory of these, once-existing, complex entries.

> You can always access the (real,imaginary) part of a complex array
> with (pot_ext_dimensionless.real, pot_ext_dimensionless.imag)
> But be careful, these arrays are not contiguous (they're a view into
> the complex array). That wrinkle has bitten me before, but I can't
> quite recall the circumstances.  You can always make them contiguous
> with numpy.ascontiguousarray().

This sounds important and not 100% clear to me. Do you mean that if I 
have a complex array z and call real.z, I do not get in general an array 
with the same length as z, since purely imaginary entries are "skipped" 
rather than appearing as entries with zero real part, as one would expect?
Many thanks


More information about the SciPy-user mailing list