为什么 Python 中的复数用“j”而不是“i”表示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24812444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why are complex numbers in Python denoted with 'j' instead of 'i'?
提问by Eli Rose -- REINSTATE MONICA
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-number literals, so I don't have anything to compare against, but does anyone know any that do use i?
我知道这是一个电气工程惯例,但我仍然想知道为什么选择它用于 Python。我不知道其他具有复数文字的编程语言,所以我没有什么可以比较的,但是有人知道使用 i 的吗?
采纳答案by Bill the Lizard
It appears to be, as you guessed, because Python follows the electrical engineering convention. Here's an exchange from the Python bug tracker Issue10562:
正如您所猜测的那样,这似乎是因为 Python 遵循电气工程惯例。这是来自 Python 错误跟踪器Issue10562的交流:
Bo?tjan Mejak: In Python, the letter 'j' denotes the imaginary unit. It would be great if we would follow mathematics in this regard and let the imaginary unit be denoted with an 'i'.
Michael Foord: We follow engineering which uses j.
(I was about to close this as wontfix but Antoine is particularly keen that Mark deals with this issue...)
Mark Dickinson: Just to add my own thoughts: 'j' for a(not the) square root of -1 has, as Michael points out, a history of use in engineering (particularly electrical engineering) and physics. Personally, I would have preferred 'i' to 'j' here, but changing it now would cause (IMO) gratuitous breakage. It really doesn't seem a big enough issue to be worth making a fuss about.
Bo?tjan Mejak:在 Python 中,字母“j”表示虚数单位。如果我们在这方面遵循数学,并让虚数单位用“i”表示,那就太好了。
Michael Foord:我们遵循使用 j 的工程。
(我正要关闭它作为 wontfix 但 Antoine 特别热衷于 Mark 处理这个问题......)
马克狄金森:我想补充我自己的想法:“J”的一个(不的)-1平方根有,迈克尔指出,在工程使用的历史(特别是电气工程)和物理。就个人而言,我更喜欢在这里使用“i”而不是“j”,但现在更改它会导致(IMO)无故损坏。这似乎真的不是一个值得大惊小怪的大问题。
...
...
Much later:
很久以后:
Guido van Rossum: This will not be fixed. For one thing, the letter 'i' or upper case 'I' look too much like digits. The way numbers are parsed either by the language parser (in source code) or by the built-in functions (int, float, complex) should not be localizable or configurable in any way; that's asking for huge disappointments down the road. If you want to parse complex numbers using 'i' instead of 'j', you have plenty of solutions available already.
Guido van Rossum:这不会被修复。一方面,字母“i”或大写“I”看起来太像数字了。语言解析器(在源代码中)或内置函数(int、float、complex)解析数字的方式不应以任何方式本地化或配置;这要求在未来的道路上大失所望。如果您想使用 'i' 而不是 'j' 解析复数,您已经有很多可用的解决方案。
回答by Andy
Python adopted the convention used by electrical engineers. In that field, i
is used to represent current and use j
as the square root of -1.
Python 采用了电气工程师使用的约定。在该字段中,i
用于表示电流并j
用作 -1 的平方根。
There was a buglogged to change it to i
in Python 3.3. It was resolves as a "WONTFIX" with this reasoning by Guido van Rossum:
在 Python 3.3 中记录了一个错误以将其更改为i
。根据Guido van Rossum 的推理,它被解析为“WONTFIX” :
This will not be fixed. For one thing, the letter 'i' or upper case 'I' look too much like digits. The way numbers are parsed either by the language parser (in source code) or by the built-in functions (int, float, complex) should not be localizable or configurable in any way; that's asking for huge disappointments down the road. If you want to parse complex numbers using 'i' instead of 'j', you have plenty of solutions available already.
这不会被修复。一方面,字母“i”或大写“I”看起来太像数字了。语言解析器(在源代码中)或内置函数(int、float、complex)解析数字的方式不应以任何方式本地化或配置;这要求在未来的道路上大失所望。如果您想使用 'i' 而不是 'j' 解析复数,您已经有很多可用的解决方案。
回答by Oleksii
j (not J) is used in Electrical Engineering as mentioned before. i for current: yes, both I (dc) and i (ac) are used for current.
如前所述,j(不是 J)用于电气工程。i 代表电流:是的,I (dc) 和 i (ac) 都用于电流。
回答by Nick Matteo
To answer "does anyone know any [other programming languages with complex-number literals] that do use i?"
回答“有没有人知道使用 i 的任何[具有复数文字的其他编程语言]?”
Yes, C++ since the C++14 standard. You have to use the right namespace though:
是的,自 C++14 标准以来的 C++。不过,您必须使用正确的命名空间:
#include <complex>
using namespace std::complex_literals;
std::complex<double> z = 2 + 3i;
回答by user10973708
i in electrical engineering is typically used for i(t) or instantaneous current. I is for steady state DC (non-complex) or rms values of AC current. In addition spacial coordinates are generally expressed as i,j,k but for two dimensional items i,j are all that are needed and the "i" is dropped so the perpendicular "j" is used as in 4j3 vs 4+3i or 4i3 -See that this is not 413 at a glance. J recognizes this notation in handling complex numbers. As a retired EE prof- I do like the use of "j" As for Current density "J" is used.
i 在电气工程中通常用于 i(t) 或瞬时电流。I 用于稳态 DC(非复数)或 AC 电流的 rms 值。此外,空间坐标通常表示为 i,j,k,但对于二维项,i,j 都是需要的,“i”被丢弃,因此垂直“j”用于 4j3 vs 4+3i 或 4i3 - 一看就知道这不是413。J 在处理复数时认识到这种表示法。作为一名退休的 EE 教授,我确实喜欢使用“j”。对于电流密度,使用“J”。