Why are complex numbers in Python denoted as "j" instead of "i"?

I know this is an electrical engineering convention, but I'm still wondering why it was chosen for Python. I don’t know other programming languages ​​with complex literals, so I have nothing to compare, but does anyone know who uses i?

+38
python
Jul 17 '14 at 19:59
source share
5 answers

It seems that, you guessed it, Python follows the electrical convention. Here's the exchange with the Python Issue10562 Python debugger :

Boštjan Mejak . In Python, the letter "j" stands for an imaginary unit. It would be great if we followed the math in this regard and designated the imaginary unit with the help of "i".

Michael Foor : We follow engineering that uses j.

(I was going to close this as wontfix, but Antoine is particularly passionate about Mark dealing with this issue ...)

Mark Dickinson . Just add your own thoughts: the “j” for the (and not) square root of -1 has, as Michael points out, a history of use in engineering (especially electrical engineering) and physics. Personally, I would prefer "i" to "j" here, but now changing it will cause messy breakdown (IMO). This really doesn't seem to be a big enough problem to think about.

...

Much later:

Guido van Rossum . This will not be fixed. Firstly, the letter "i" or uppercase "I" is too much like numbers. Number paths are analyzed either by a language parser (in the source code) or by built-in functions (int, float, complex) should not be localizable or customizable in any way; who ask for huge disappointments in the future. If you want to analyze complex numbers using "i" instead of "j", you already have many solutions available.

+28
Jul 17 '14 at 20:11
source share

Python has adopted the convention used by electrical engineers. In this field, i used to represent the current and j used as the square root of -1.

A bug was registered to change it to i in Python 3.3. This was decided as "WONTFIX" with this reasoning by Guido van Rossum :

This will not be fixed. First, the letter "i" or uppercase "I" is too much like numbers. The number paths are analyzed either by the language analyzer (in the source code) or the built-in functions (int, float, complex) should not be localizable or customizable in any way; who ask for huge disappointments in the future. If you want to analyze complex numbers using "i" instead of "j", you have many existing solutions.

+12
Jul 17 '14 at 20:09
source share

To answer "Does anyone know any [other programming languages ​​with complex literals] that use i?"

Yes, C ++ from the C ++ 14 standard. You must use the correct namespace:

 #include <complex> using namespace std::complex_literals; std::complex<double> z = 2 + 3i; 
+5
May 30 '16 at 13:53
source share

j (not J) is used in electrical engineering, as mentioned earlier. i for current: yes, both i (dc) and i (ac) are used for current.

0
May 30 '16 at 13:42
source share

i in electrical engineering is commonly used for i (t) or instantaneous current. i for a constant state (not complex) or rms ac. In addition, spatial coordinates are usually expressed as i, j, k, but for two-dimensional elements i, j is all that is needed and the “i” is discarded, so the perpendicular “j” is used, as in 4j3 versus 4 + 3i or 4i3 . -See that this is not 413 at a glance. J recognizes this entry in complex number processing. As a retired EE prof- I like to use "j". As for the current density, "J" is used.

0
Jan 27 '19 at 5:08
source share



All Articles