Re: trouble with complex numbers

2009-08-05 Thread Steven D'Aprano
On Wed, 05 Aug 2009 15:27:51 -0500, Robert Kern wrote: > On 2009-08-05 15:16, Dr. Phillip M. Feldman wrote: >> I am using Python 2.5, and most of the cmath functions are not yet >> available in this version. Thanks! >> >> Phillip >> >> P.S. In your code, that should be x+= 0J >> >> P.P.S. I wish

Re: trouble with complex numbers

2009-08-05 Thread Robert Kern
On 2009-08-05 15:16, Dr. Phillip M. Feldman wrote: I am using Python 2.5, and most of the cmath functions are not yet available in this version. Thanks! Phillip P.S. In your code, that should be x+= 0J P.P.S. I wish that the documentation indicated anything that is new. It does. http://doc

Re: trouble with complex numbers

2009-08-05 Thread Dr. Phillip M. Feldman
on-list > > -- View this message in context: http://www.nabble.com/trouble-with-complex-numbers-tp24821423p24835436.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: trouble with complex numbers

2009-08-05 Thread pdlemper
On Wed, 05 Aug 2009 08:18:55 -0700, Scott David Daniels wrote: >I think it explained in the complex math area, but basically EE types >use j, math types use i for exactly the same thing. Since i is so >frequently and index in CS, and there is another strong convention, >why not let the EE types

Re: trouble with complex numbers

2009-08-05 Thread alex23
On Aug 6, 1:18 am, Scott David Daniels wrote: > I think it explained in the complex math area, but basically EE types > use j, math types use i for exactly the same thing.  Since i is so > frequently and index in CS, and there is another strong convention, > why not let the EE types win? That 'i'

Re: trouble with complex numbers

2009-08-05 Thread Scott David Daniels
alex23 wrote: Piet van Oostrum wrote: That should be z += 0j Pardon my ignorance, but could anyone explain the rationale behind using 'j' to indicate the imaginary number (as opposed to the more intuitive 'i')? (Not that I've had much call to use complex number

Re: trouble with complex numbers

2009-08-05 Thread alex23
Piet van Oostrum wrote: > That should be z += 0j Pardon my ignorance, but could anyone explain the rationale behind using 'j' to indicate the imaginary number (as opposed to the more intuitive 'i')? (Not that I've had much call to use complex numbers b

Re: trouble with complex numbers

2009-08-05 Thread Piet van Oostrum
> Christian Heimes (CH) wrote: >CH> You can write your own phase() function. This function is mostly correct >CH> unless either the real and/or the imag part is NaN or INF. >CH> from math import atan2 >CH> def phase(z): >CH> z += 1j # convert int, long, float to complex That should be

Re: trouble with complex numbers

2009-08-05 Thread Christian Heimes
Dr. Phillip M. Feldman wrote: When I try to compute the phase of a complex number, I get an error message: In [3]: from cmath import * In [4]: x=1+1J In [5]: phase(x) NameError: name 'phase' is not defined AttributeError: 'complex' object has no attribute 'phase' Any advice will be appreciate

Re: trouble with complex numbers

2009-08-05 Thread alex23
On Aug 5, 4:28 pm, "Dr. Phillip M. Feldman" wrote: > When I try to compute the phase of a complex number, I get an error message: > [...] > Any advice will be appreciated. 1. What version of Python are you using, and on what platform? 2. What you snipped is necessary to help debug your problem.

Re: trouble with complex numbers

2009-08-05 Thread Chris Rebert
On Tue, Aug 4, 2009 at 11:28 PM, Dr. Phillip M. Feldman wrote: > > When I try to compute the phase of a complex number, I get an error message: > > In [3]: from cmath import * > In [4]: x=1+1J > In [5]: phase(x) > > NameError: name 'phase' is not defined > > AttributeError: 'complex' object has n

trouble with complex numbers

2009-08-05 Thread Dr. Phillip M. Feldman
ated. -- View this message in context: http://www.nabble.com/trouble-with-complex-numbers-tp24821423p24821423.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting list of complex numbers

2008-11-21 Thread Tim Golden
Steven D'Aprano wrote: On Wed, 19 Nov 2008 18:39:27 -0800, Paul Rubin wrote: Terry Reedy <[EMAIL PROTECTED]> writes: Do your tuple destructuring in the first statement in your body and nothing will break. Why get rid of a useful feature that unclutters code? Unfortunately, the people who fi

Re: sorting list of complex numbers

2008-11-20 Thread Steven D'Aprano
On Wed, 19 Nov 2008 18:39:27 -0800, Paul Rubin wrote: > Terry Reedy <[EMAIL PROTECTED]> writes: >> >> Do your tuple destructuring in the first statement in your body and >> >> nothing will break. > > Why get rid of a useful feature that unclutters code? Unfortunately, the people who find it usef

Re: sorting list of complex numbers

2008-11-19 Thread Terry Reedy
Paul Rubin wrote: Terry Reedy <[EMAIL PROTECTED]> writes: Do your tuple destructuring in the first statement in your body and nothing will break. Why get rid of a useful feature that unclutters code? Because, as has been posted before, it is rarely used, it is replaceable, its presence inte

Re: sorting list of complex numbers

2008-11-19 Thread Paul Rubin
Terry Reedy <[EMAIL PROTECTED]> writes: > >> Do your tuple destructuring in the first statement in your body and > >> nothing will break. Why get rid of a useful feature that unclutters code? > > Unless you were using a lambda, which is quite useful as argument to > > "sort". > > So write a sepa

Re: sorting list of complex numbers

2008-11-19 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: >> Terry Reedy <[EMAIL PROTECTED]> writes: >> >>> Do your tuple destructuring in the first statement in your body and >>> nothing will break. >> >> Unless you were using a lambda, which is quite useful as argument to >> "sort". > > So

Re: sorting list of complex numbers

2008-11-19 Thread Terry Reedy
Hrvoje Niksic wrote: Terry Reedy <[EMAIL PROTECTED]> writes: Do your tuple destructuring in the first statement in your body and nothing will break. Unless you were using a lambda, which is quite useful as argument to "sort". So write a separate def statement. If you do not want to do that,

Re: sorting list of complex numbers

2008-11-19 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes: > Do your tuple destructuring in the first statement in your body and > nothing will break. Unless you were using a lambda, which is quite useful as argument to "sort". -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting list of complex numbers

2008-11-18 Thread Terry Reedy
Paul Rubin wrote: That only goes so far though. Suppose instead of complex numbers you want to sort expressions, like: a(b,c(d,e),f(g,h)) treat those as parse trees in the obvious way. Presuming that a, c, and f are function calls that return Tree instances, you give Tree a __lt__

Re: sorting list of complex numbers

2008-11-18 Thread Arnaud Delobelle
Paul Rubin writes: > for fancier structures you'd need a full blown class implementation > with an init method. Either way you end up temporarily allocating a > lot of extra structures, but at least they're not all in memory > simultaneously like in the DSU pattern. Th

Re: sorting list of complex numbers

2008-11-18 Thread Gabriel Genellina
En Tue, 18 Nov 2008 08:41:58 -0200, Paul Rubin <"http://phr.cx"@nospam.invalid> escribió: [EMAIL PROTECTED] writes: but how do I then do a secondary sort by the imaginary part,... Is there a way to do this using just the key arg, no extra data structures? Clever solutions involving multip

Re: sorting list of complex numbers

2008-11-18 Thread Paul Rubin
[EMAIL PROTECTED] writes: > but how do I then do a secondary sort by the imaginary part,... > Is there a way to do this using just the key arg, no extra data structures? Clever solutions involving multiple sorts aside, I think what they really want you to do is something like (untested): clas

Re: sorting list of complex numbers

2008-11-18 Thread Paul Rubin
Duncan Booth <[EMAIL PROTECTED]> writes: > If you don't like the tuple then just do the two sorts separately: > > >>> lst.sort(key=lambda x: x.imag) > >>> lst.sort(key=lambda x: x.real) > >>> pprint.pprint(lst) That only goes so far though.

Re: sorting list of complex numbers

2008-11-11 Thread Steve Holden
Thomas Bellman wrote: > Steve Holden <[EMAIL PROTECTED]> wrote: > >> Only half the number, of course. The advantage of the key function is >> that each element requires only one call out to a Python function, and >> the comparisons then take place using a C-coded comparison function. > > You don'

Re: sorting list of complex numbers

2008-11-11 Thread Thomas Bellman
Steve Holden <[EMAIL PROTECTED]> wrote: > Only half the number, of course. The advantage of the key function is > that each element requires only one call out to a Python function, and > the comparisons then take place using a C-coded comparison function. You don't need any Python-coded function

Re: sorting list of complex numbers

2008-11-09 Thread skip
>> Timeit suggests the single sort returning the real, imag tuples is >> faster than two sorts each on one field, as you might expect since >> many fewer calls to the key function are made. Steve> Only half the number, of course. The advantage of the key Steve> function is tha

Re: sorting list of complex numbers

2008-11-09 Thread Steve Holden
[EMAIL PROTECTED] wrote: [...] > Duncan> If you don't like the tuple then just do the two sorts separately: > > lst.sort(key=lambda x: x.imag) > lst.sort(key=lambda x: x.real) > ... > > I tried that. I could have sworn when I read through the output it hadn't > retained

Re: sorting list of complex numbers

2008-11-09 Thread Terry Reedy
[EMAIL PROTECTED] wrote: Duncan> If you don't like the tuple then just do the two sorts separately: lst.sort(key=lambda x: x.imag) lst.sort(key=lambda x: x.real) ... I tried that. I could have sworn when I read through the output it hadn't retained the order of the r

Re: sorting list of complex numbers

2008-11-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: The thread on sorting in Python 3 got me to thinking. How could I sort a list of complex numbers using key? >>> lst = [random.random()+random.random()*1j for i in range(10)] >>> lst [(0.32672251849959244+0.41428983433288791j), (0

Re: sorting list of complex numbers

2008-11-09 Thread skip
>> Is there a way to do this using just the key arg, no extra data >> structures? Duncan> Is a tuple an extra data structure? lst.sort(key=lambda x: (x.real,x.imag)) pprint.pprint(lst) Duncan> [2.6001j, Duncan> 20j, Duncan> (1+2.73j), D

Re: sorting list of complex numbers

2008-11-09 Thread Duncan Booth
8+3.6401j), > (9+3.77j), > (9+29j)] > > but how do I then do a secondary sort by the imaginary part, preserving the > existing ordering on the real parts? Seems like I have to resort to a > Schwartzian transform and map the complex numbers to tuples, sort

sorting list of complex numbers

2008-11-09 Thread skip
The thread on sorting in Python 3 got me to thinking. How could I sort a list of complex numbers using key? >>> lst = [random.random()+random.random()*1j for i in range(10)] >>> lst [(0.32672251849959244+0.41428983433288791j), (0.35238056484609881+0.

Re: complex numbers should respect the "I" representation

2008-06-30 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hi > > I think complex numbers should respect the "i" or "I" representation, > instead of "j". > No reason being cute and using a different chara

Re: complex numbers should respect the "I" representation

2008-06-29 Thread Lie
On Jun 29, 8:39 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-06-29, Roy Smith <[EMAIL PROTECTED]> wrote: > > >> I think complex numbers should respect the "i" or "I" > >> representation, instead of "j". No reason being cu

Re: complex numbers should respect the "I" representation

2008-06-29 Thread Grant Edwards
On 2008-06-29, Roy Smith <[EMAIL PROTECTED]> wrote: >> I think complex numbers should respect the "i" or "I" >> representation, instead of "j". No reason being cute and using >> a different character instead of the traditional >> repres

Re: complex numbers should respect the "I" representation

2008-06-28 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hi > > I think complex numbers should respect the "i" or "I" representation, > instead of "j". > No reason being cute and using a differ

Re: complex numbers should respect the "I" representation

2008-06-28 Thread Mark Dickinson
On Jun 28, 1:48 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hi > > I think complex numbers should respect the "i" or "I" representation, > instead of "j". > No reason being cute and using a different character instead of t

Re: complex numbers should respect the "I" representation

2008-06-28 Thread Ant
On Jun 28, 1:48 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I think complex numbers should respect the "i" or "I" representation, > instead of "j". > No reason being cute and using a different character instead of the > tradition

complex numbers should respect the "I" representation

2008-06-28 Thread [EMAIL PROTECTED]
hi I think complex numbers should respect the "i" or "I" representation, instead of "j". No reason being cute and using a different character instead of the traditional representation? At least have the decency of supporting the orginal representation? Programme

Re: Problem with complex numbers

2008-03-23 Thread David C. Ullrich
On Sat, 22 Mar 2008 23:29:10 +0100, Christian Heimes <[EMAIL PROTECTED]> wrote: >Matthias Götz schrieb: >> So can you tell me what's the purpose of Complex.py, >> >> and where can i find the semantic i'am looking for. > >Well, the file is in the Demo folder. It's just a demo how to implement >a n

Re: Problem with complex numbers

2008-03-22 Thread Terry Reedy
"Christian Heimes" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Well, the file is in the Demo folder. It's just a demo how to implement a naive complex type in Python. | Why do you think the power of a complex to a complex is not defined? I suspect because the naive implementa

Re: Problem with complex numbers

2008-03-22 Thread Christian Heimes
Matthias Götz schrieb: > So can you tell me what's the purpose of Complex.py, > > and where can i find the semantic i'am looking for. Well, the file is in the Demo folder. It's just a demo how to implement a naive complex type in Python. Why do you think the power of a complex to a complex is no

Re: Problem with complex numbers

2008-03-22 Thread Christian Heimes
Matthias Götz schrieb: > So if somebody can help me, it would be nice. Thanks. The complex type is implemented in C. It's totally unrelated to Complex.py. Christian -- http://mail.python.org/mailman/listinfo/python-list

Problem with complex numbers

2008-03-22 Thread Matthias Götz
return Complex(math.cos(phi)*r, math.sin(phi)*r) which mean for example if i calculate z1 power z2 (z1,z2 are complex numbers), and z1 and z2 has imaginary parts not equals zero, i must get an TypeError. Is that right? But i tried that in the IDLE python shell by doing this >>>

Complex Numbers

2007-08-31 Thread Greg Lindstrom
for place > holders to try to find the answer type complex numbers? Not quite. Consider the square root of -1. It's not real because you can't square a real number and get a negative, so we define "i" (or, perhaps "j") to be the square root of -1. An imagin

Re: ctypes and C99 complex numbers

2007-08-16 Thread Martin v. Löwis
Thomas Heller schrieb: > Eugen Wintersberger schrieb: >> Hi there >> I want to use ctypes in connection with C functions that use complex >> datatypes defined in the C99 standard. Does someone know a simple way >> how to implement this? Are there any plans to integrate the C99 complex >> data type

Re: ctypes and C99 complex numbers

2007-08-16 Thread Thomas Heller
Eugen Wintersberger schrieb: > Hi there > I want to use ctypes in connection with C functions that use complex > datatypes defined in the C99 standard. Does someone know a simple way > how to implement this? Are there any plans to integrate the C99 complex > data types in the ctypes module? I hav

ctypes and C99 complex numbers

2007-08-16 Thread Eugen Wintersberger
Hi there I want to use ctypes in connection with C functions that use complex datatypes defined in the C99 standard. Does someone know a simple way how to implement this? Are there any plans to integrate the C99 complex data types in the ctypes module? best regards Eugen Wintersberger --

Re: Mutable complex numbers [was Re: output formatting for classes]

2006-03-11 Thread Schüle Daniel
e value 1+1j > > Objects with indeterminate values are rarely a good idea. IMHO it's perfectly consistent with >>> int() 0 >>> long() 0L >>> float() 0.0 >>> complex() >>> complex() 0j >>> but extending complex with default

Mutable complex numbers [was Re: output formatting for classes]

2006-03-10 Thread Steven D'Aprano
here? c.abs = 2**0.5 => what is c's value now? c.angle = pi/2 => now c has the value 1+1j Objects with indeterminate values are rarely a good idea. A better way would be for complex numbers to take a constructor that can take arguments in either Cartesian or polar form. So, hypothetic

Re: complex numbers

2005-01-13 Thread Antoon Pardon
Op 2005-01-12, It's me schreef <[EMAIL PROTECTED]>: > Precisely. One have to convert complex number into vectors, and vector of > complex numbers into vector of vectors, list of complex numbers into list of > vectors, , you get the idea. Wrong. My vector example was an i

Re: complex numbers

2005-01-12 Thread Scott David Daniels
Robert Kern wrote: Let's presume for a moment that complex is *not* a native data type in Python. How would we implement the above - cleanly? The reason for making complex a builtin is _not_ to ease a single program, but to create a convention allowing different modules which operate on co

Re: complex numbers

2005-01-12 Thread Carl Banks
It's me wrote: > The world would come to a halt if all of a sudden nobody understands complex > numbers anymore. :-) Actually, it would oscillate out of control. -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list

Re: complex numbers

2005-01-12 Thread Terry Reedy
"It's me" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Precisely. One have to convert complex number into vectors, and vector > of > complex numbers into vector of vectors, list of complex numbers into list > of > vectors, , you get t

Re: complex numbers

2005-01-12 Thread Robert Kern
presume for a moment that complex is *not* a native data type in Python. How would we implement the above - cleanly? The way it's implemented now. See the file Object/complexobject.c for details. Numeric operations on ints, longs, floats, and complex numbers are all implemented using operat

Re: complex numbers

2005-01-12 Thread It's me
Precisely. One have to convert complex number into vectors, and vector of complex numbers into vector of vectors, list of complex numbers into list of vectors, , you get the idea. And my code no longer look like the equation I have on paper... Like I said, I've travelled down that

Re: complex numbers

2005-01-12 Thread Antoon Pardon
>>> twice(Vec(1.0,2.0)) Vector[2.0, 4.0] >>> I suppose what can be done with a vector class could have been done with a complex class should complex numbers not have been native to python. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list

Re: complex numbers

2005-01-11 Thread It's me
"Robert Kern" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > That's *it*. So, how would you overload an operator to do: With native complex support: def twice(a): return 2*a print twice(3+4j), twice(2), twice("abc") Let's presume for a moment that complex is *not* a nati

Re: complex numbers

2005-01-11 Thread Robert Kern
It's me wrote: You are focusing on computational type applications of complex numbers. For those, you can do it with any languages - including machine language. It's just a matter of how much headache you want. For instance, when constructing "software lego parts" (such as

Re: complex numbers

2005-01-11 Thread It's me
You are focusing on computational type applications of complex numbers. For those, you can do it with any languages - including machine language. It's just a matter of how much headache you want. For instance, when constructing "software lego parts" (such as the Matlab/Simulink t

Re: complex numbers

2005-01-11 Thread It's me
"Big and Blue" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > It's me wrote: > > > > I am very happy that Python included *native* complex number > > support. > > And I have always been happy that FORTRAN supports them. > > > I really like Python's notion of hav

Re: complex numbers

2005-01-11 Thread Big and Blue
It's me wrote: > I am very happy that Python included *native* complex number support. And I have always been happy that FORTRAN supports them. I really like Python's notion of having just one data type: the duck. So have you considered using Python for your problem? --

Re: complex numbers

2005-01-11 Thread Anno Siegel
gt; > > my $z = sqrt( -1); > > print 1 + $z, "\n"; # prints "1+i" > > > > Operator overloading makes it possible to work with complex numbers as if > > they were a native data type. > Operator overloading (and function overloading) helps but no

Re: complex numbers

2005-01-11 Thread It's me
uot;\n"; # prints "1+i" > > Operator overloading makes it possible to work with complex numbers as if > they were a native data type. > > Anno > -- http://mail.python.org/mailman/listinfo/python-list

Re: complex numbers

2005-01-11 Thread Anno Siegel
It's me <[EMAIL PROTECTED]> wrote in comp.lang.perl.misc: [reply moved to bottom into context] > "Jürgen Exner" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > [EMAIL PROTECTED] wrote: > > > #python supports complex numbers. >

Re: complex numbers

2005-01-10 Thread It's me
For those of us that works with complex numbers, having complex number as a natively supported data type is a big advantage. Non-native add-ons are not sufficient and lead to very awkward program code. "Jürgen Exner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] &g

Re: complex numbers

2005-01-10 Thread Alfred Z. Newmane
J|rgen Exner wrote: > [EMAIL PROTECTED] wrote: >> #python supports complex numbers. > [...] > > So? > >> # Perl doesn't support complex numbers. But there are packages that >> supports it. > > The Math::Complex module is part of the standard insta

Re: complex numbers

2005-01-09 Thread Jürgen Exner
[EMAIL PROTECTED] wrote: > #python supports complex numbers. [...] So? > # Perl doesn't support complex numbers. But there are packages that > supports it. The Math::Complex module is part of the standard installation already, no need for any "packages" (whatever that