Why does (inf + 0j)*1 evaluate to inf + nanj?What does ** (double star/asterisk) and * (star/asterisk) do for...
Is "ln" (natural log) and "log" the same thing if used in this answer?
How to deal with my team leader who keeps calling me about project updates even though I am on leave for personal reasons?
What is the need of methods like GET and POST in the HTTP protocol?
Is it impolite to ask for an in-flight catalogue with no intention of buying?
Does the Prepare Food ability from Cook's Utensils stack?
Cut a cake into 3 equal portions with only a knife
Could Apollo astronauts see city lights from the moon?
Extruding snaps back
How can this Stack Exchange site have an animated favicon?
Do we have any particular tonal center in mind when we are NOT listening music?
Safely hang a mirror that does not have hooks
Should the average user with no special access rights be worried about SMS-based 2FA being theoretically interceptable?
When is it acceptable to write a bad letter of recommendation?
Designing a time thief proof safe
Social leper versus social leopard
2000s Animated TV show where teenagers could physically go into a virtual world
What secular civic space would pioneers build for small frontier towns?
Guitar tuning (EADGBE), "perfect" fourths?
If an object moving in a circle experiences centripetal force, then doesn't it also experience centrifugal force, because of Newton's third law?
A food item only made possible by time-freezing storage?
Going to France with limited French for a day
What can a pilot do if an air traffic controller is incapacitated?
Meaning of 'ran' in German?
while loop factorial only works up to 20?
Why does (inf + 0j)*1 evaluate to inf + nanj?
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?Python join: why is it string.join(list) instead of list.join(string)?What is the rationale for all comparisons returning false for IEEE754 NaN values?Does Python have a string 'contains' substring method?Why is reading lines from stdin much slower in C++ than Python?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
>>> from numpy import inf, nan
>>> z = (inf+0j)*1
(inf+nanj)
Why? This caused a nasty bug in my code.
Why isn't 1
the multiplicative identity, giving (inf + 0j)
?
python numpy nan ieee-754
add a comment
|
>>> from numpy import inf, nan
>>> z = (inf+0j)*1
(inf+nanj)
Why? This caused a nasty bug in my code.
Why isn't 1
the multiplicative identity, giving (inf + 0j)
?
python numpy nan ieee-754
add a comment
|
>>> from numpy import inf, nan
>>> z = (inf+0j)*1
(inf+nanj)
Why? This caused a nasty bug in my code.
Why isn't 1
the multiplicative identity, giving (inf + 0j)
?
python numpy nan ieee-754
>>> from numpy import inf, nan
>>> z = (inf+0j)*1
(inf+nanj)
Why? This caused a nasty bug in my code.
Why isn't 1
the multiplicative identity, giving (inf + 0j)
?
python numpy nan ieee-754
python numpy nan ieee-754
edited 57 mins ago
Peter Cordes
158k23 gold badges254 silver badges406 bronze badges
158k23 gold badges254 silver badges406 bronze badges
asked 11 hours ago
marnixmarnix
1076 bronze badges
1076 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
The 1
is converted to a complex number first, 1 + 0j
, which then leads to an inf * 0
multiplication, resulting in a nan
.
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j
3
For answering the question "why...?", probably the important most step is the first one, where1
is cast to1 + 0j
.
– Warren Weckesser
11 hours ago
add a comment
|
To find the "true" reason---as opposed to the purely mechanical reason given in the accepted answer---one probably has to start with something like https://math.stackexchange.com/q/628947
A previous version of the question title was worded "Why is (inf + 0j)*1 == inf + nanj?"
That is not in fact the case because nan == nan
is false:
from math import inf
(inf+0j)*1==complex("inf+nanj")
# False
3
Yeah, becausenan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.
– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).
– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work oninf + 0j
?
– Peter Cordes
51 mins ago
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58031966%2fwhy-does-inf-0j1-evaluate-to-inf-nanj%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The 1
is converted to a complex number first, 1 + 0j
, which then leads to an inf * 0
multiplication, resulting in a nan
.
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j
3
For answering the question "why...?", probably the important most step is the first one, where1
is cast to1 + 0j
.
– Warren Weckesser
11 hours ago
add a comment
|
The 1
is converted to a complex number first, 1 + 0j
, which then leads to an inf * 0
multiplication, resulting in a nan
.
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j
3
For answering the question "why...?", probably the important most step is the first one, where1
is cast to1 + 0j
.
– Warren Weckesser
11 hours ago
add a comment
|
The 1
is converted to a complex number first, 1 + 0j
, which then leads to an inf * 0
multiplication, resulting in a nan
.
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j
The 1
is converted to a complex number first, 1 + 0j
, which then leads to an inf * 0
multiplication, resulting in a nan
.
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j
edited 11 hours ago
Engineero
7,3543 gold badges26 silver badges52 bronze badges
7,3543 gold badges26 silver badges52 bronze badges
answered 11 hours ago
MaratMarat
4,9771 gold badge20 silver badges34 bronze badges
4,9771 gold badge20 silver badges34 bronze badges
3
For answering the question "why...?", probably the important most step is the first one, where1
is cast to1 + 0j
.
– Warren Weckesser
11 hours ago
add a comment
|
3
For answering the question "why...?", probably the important most step is the first one, where1
is cast to1 + 0j
.
– Warren Weckesser
11 hours ago
3
3
For answering the question "why...?", probably the important most step is the first one, where
1
is cast to 1 + 0j
.– Warren Weckesser
11 hours ago
For answering the question "why...?", probably the important most step is the first one, where
1
is cast to 1 + 0j
.– Warren Weckesser
11 hours ago
add a comment
|
To find the "true" reason---as opposed to the purely mechanical reason given in the accepted answer---one probably has to start with something like https://math.stackexchange.com/q/628947
A previous version of the question title was worded "Why is (inf + 0j)*1 == inf + nanj?"
That is not in fact the case because nan == nan
is false:
from math import inf
(inf+0j)*1==complex("inf+nanj")
# False
3
Yeah, becausenan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.
– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).
– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work oninf + 0j
?
– Peter Cordes
51 mins ago
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
add a comment
|
To find the "true" reason---as opposed to the purely mechanical reason given in the accepted answer---one probably has to start with something like https://math.stackexchange.com/q/628947
A previous version of the question title was worded "Why is (inf + 0j)*1 == inf + nanj?"
That is not in fact the case because nan == nan
is false:
from math import inf
(inf+0j)*1==complex("inf+nanj")
# False
3
Yeah, becausenan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.
– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).
– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work oninf + 0j
?
– Peter Cordes
51 mins ago
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
add a comment
|
To find the "true" reason---as opposed to the purely mechanical reason given in the accepted answer---one probably has to start with something like https://math.stackexchange.com/q/628947
A previous version of the question title was worded "Why is (inf + 0j)*1 == inf + nanj?"
That is not in fact the case because nan == nan
is false:
from math import inf
(inf+0j)*1==complex("inf+nanj")
# False
To find the "true" reason---as opposed to the purely mechanical reason given in the accepted answer---one probably has to start with something like https://math.stackexchange.com/q/628947
A previous version of the question title was worded "Why is (inf + 0j)*1 == inf + nanj?"
That is not in fact the case because nan == nan
is false:
from math import inf
(inf+0j)*1==complex("inf+nanj")
# False
edited 52 mins ago
Peter Cordes
158k23 gold badges254 silver badges406 bronze badges
158k23 gold badges254 silver badges406 bronze badges
answered 9 hours ago
Paul PanzerPaul Panzer
35.6k2 gold badges23 silver badges54 bronze badges
35.6k2 gold badges23 silver badges54 bronze badges
3
Yeah, becausenan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.
– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).
– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work oninf + 0j
?
– Peter Cordes
51 mins ago
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
add a comment
|
3
Yeah, becausenan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.
– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).
– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work oninf + 0j
?
– Peter Cordes
51 mins ago
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
3
3
Yeah, because
nan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.– cmaster
3 hours ago
Yeah, because
nan != nan
. I understand that this answer is half-joking, but I fail to see why it should be helpful to the OP the way it's written.– cmaster
3 hours ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Why don't you heros take a step back and ask yourselves why you seem uncapable of venting your righteous indignation without patronizing the OP? And if---one may hope---you come to conclude it is yourself who do not follow, there is no shame in asking.
– Paul Panzer
1 hour ago
Given that the code in the question body wasn't actually using
==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).– Peter Cordes
55 mins ago
Given that the code in the question body wasn't actually using
==
(and given they accepted the other answer), it seems it was just a problem of how the OP expressed the title. I reworded the title to fix that inconsistency. (Intentionally invaliding the first half of this answer because I agree with @cmaster: that isn't what this question was asking about).– Peter Cordes
55 mins ago
Is there a multiplicative identity for complex numbers that does work on
inf + 0j
?– Peter Cordes
51 mins ago
Is there a multiplicative identity for complex numbers that does work on
inf + 0j
?– Peter Cordes
51 mins ago
1
1
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
@PeterCordes that would be troubling because using polar coordinates we can view complex multiplication as a scaling and a rotation. Rotating an infinite "arm" even by 0 degrees as in the case of multiplying by one we cannot expect to place its tip with finite precision. This is in my opinion a deeper explanation than the accepted one, and also one with echos in the nan != nan rule.
– Paul Panzer
35 mins ago
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58031966%2fwhy-does-inf-0j1-evaluate-to-inf-nanj%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown