Python Packages for Complex Numbers and Matrix Math

Maan Hamze mmhamze at pleiades.net
Mon Aug 27 00:03:21 CEST 2001


Ignacio
I am quite confused by the implementation of complex numbers:
1.  Try
>>>  r = 4
>>> r.imag
Error:  int object has no attrib imag
>>> r.real
error:  int object has no attrib real

But every real/int number is a complex number with a 0 imaginary part (r =
4+0j)

2.  Also,
>>> x = 4 + 7j
>>> x.imag = 6
error:  object has a read-only attrib
>>> x.real = 7
same error of read-olny attrib

why?

3.  Finally,
>>> t.imag = 6
error:  name 't' is not defined    (you expect this to set t=6j without
further ado)
>>> t.real = 7
error: name 't' is not defined    (you expect this to set t=7 automatically)
Is not this lame :O
In this case, one expects:
>>> t.imag = 7
>>> t
7j
>>> t.real = 6
>>> t
6+7j

Maan
"Ignacio Vazquez-Abrams" <ignacio at openservices.net> wrote in message
news:mailman.998851300.13860.python-list at python.org...
> On Sun, 26 Aug 2001, Maan Hamze wrote:
>
> > if x is a complex number = a + bj
> > is there any built in finction that can return the real and imaginary
values
> > of x?
> > Something like:
> > r = real(x) = a and
> > s=img(x) = b
> > I can not find something like that.
> > Maan
>
> Try x.real and x.imag.
>
> --
> Ignacio Vazquez-Abrams  <ignacio at openservices.net>
>
>





More information about the Python-list mailing list