Why is (inf + 0j)*1 == inf + nanj?Python join: why is it string.join(list) instead of list.join(string)?What...

Hilbert's hotel: why can't I repeat it infinitely many times?

Basic digital RC approximation filter in python (Micropython)

Is it true that, "just ten trading days represent 63 per cent of the returns of the past 50 years"?

Is this Portent-like spell balanced?

Can Northern Ireland's border issue be solved by repartition?

Examples of "unsuccessful" theories with afterlives

If an object moving in a circle experiences centripetal force, then doesn't it also experience centrifugal force, because of Newton's third law?

Why did UK NHS pay for homeopathic treatments?

Is it really necessary to have a four hour meeting in Sprint planning?

How can an attacker use robots.txt?

Can the U.S. president make military decisions without consulting anyone?

Social leper versus social leopard

Why does NASA publish all the results/data it gets?

Late 1970's and 6502 chip facilities for operating systems

What do you do if you have developments on your paper during the long peer review process?

When is it acceptable to write a bad letter of recommendation?

Are Custom Indexes passed on to Sandboxes

Hiking with a mule or two?

Why weren't the Death Star plans transmitted electronically?

Is this a Sherman, and if so what model?

Is it impolite to ask for an in-flight catalogue with no intention of buying?

Could Apollo astronauts see city lights from the moon?

Two trains move towards each other, a bird moves between them. How many trips can the bird make?

Is it a good idea to leave minor world details to the reader's imagination?



Why is (inf + 0j)*1 == inf + nanj?


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?Python class inherits objectWhy is reading lines from stdin much slower in C++ than Python?UnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)dropping infinite values from dataframes in pandas?Counting the number of non-NaN elements in a numpy ndarray in PythonWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Why aren't Inf, -Inf and NaN keywords in Python?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







12















>>> from numpy import inf, nan
>>> z = (inf+0j)*1
(inf+nanj)


Why? This caused a nasty bug in my code.










share|improve this question































    12















    >>> from numpy import inf, nan
    >>> z = (inf+0j)*1
    (inf+nanj)


    Why? This caused a nasty bug in my code.










    share|improve this question



























      12












      12








      12


      4






      >>> from numpy import inf, nan
      >>> z = (inf+0j)*1
      (inf+nanj)


      Why? This caused a nasty bug in my code.










      share|improve this question














      >>> from numpy import inf, nan
      >>> z = (inf+0j)*1
      (inf+nanj)


      Why? This caused a nasty bug in my code.







      python numpy nan ieee-754






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      marnixmarnix

      926 bronze badges




      926 bronze badges



























          2 Answers
          2






          active

          oldest

          votes


















          16
















          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





          share|improve this answer























          • 3





            For answering the question "why...?", probably the important most step is the first one, where 1 is cast to 1 + 0j.

            – Warren Weckesser
            8 hours ago





















          -1
















          "Why is (inf + 0j)*1 == inf + nanj"



          Actually, it isn't:



          from math import inf
          (inf+0j)*1==complex("inf+nanj")
          # False


          On a more serious note, 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






          share|improve this answer




























          • 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
            27 mins ago














          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
          });


          }
          });















          draft saved

          draft discarded
















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58031966%2fwhy-is-inf-0j1-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









          16
















          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





          share|improve this answer























          • 3





            For answering the question "why...?", probably the important most step is the first one, where 1 is cast to 1 + 0j.

            – Warren Weckesser
            8 hours ago


















          16
















          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





          share|improve this answer























          • 3





            For answering the question "why...?", probably the important most step is the first one, where 1 is cast to 1 + 0j.

            – Warren Weckesser
            8 hours ago
















          16














          16










          16









          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





          share|improve this answer















          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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago









          Engineero

          7,3543 gold badges26 silver badges52 bronze badges




          7,3543 gold badges26 silver badges52 bronze badges










          answered 8 hours ago









          MaratMarat

          4,9371 gold badge20 silver badges34 bronze badges




          4,9371 gold badge20 silver badges34 bronze badges











          • 3





            For answering the question "why...?", probably the important most step is the first one, where 1 is cast to 1 + 0j.

            – Warren Weckesser
            8 hours ago
















          • 3





            For answering the question "why...?", probably the important most step is the first one, where 1 is cast to 1 + 0j.

            – Warren Weckesser
            8 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
          8 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
          8 hours ago















          -1
















          "Why is (inf + 0j)*1 == inf + nanj"



          Actually, it isn't:



          from math import inf
          (inf+0j)*1==complex("inf+nanj")
          # False


          On a more serious note, 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






          share|improve this answer




























          • 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
            27 mins ago
















          -1
















          "Why is (inf + 0j)*1 == inf + nanj"



          Actually, it isn't:



          from math import inf
          (inf+0j)*1==complex("inf+nanj")
          # False


          On a more serious note, 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






          share|improve this answer




























          • 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
            27 mins ago














          -1














          -1










          -1









          "Why is (inf + 0j)*1 == inf + nanj"



          Actually, it isn't:



          from math import inf
          (inf+0j)*1==complex("inf+nanj")
          # False


          On a more serious note, 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






          share|improve this answer















          "Why is (inf + 0j)*1 == inf + nanj"



          Actually, it isn't:



          from math import inf
          (inf+0j)*1==complex("inf+nanj")
          # False


          On a more serious note, 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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 3 hours ago

























          answered 7 hours ago









          Paul PanzerPaul Panzer

          35.6k2 gold badges23 silver badges54 bronze badges




          35.6k2 gold badges23 silver badges54 bronze badges
















          • 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
            27 mins 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
            27 mins 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
          27 mins 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
          27 mins ago



















          draft saved

          draft discarded



















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58031966%2fwhy-is-inf-0j1-inf-nanj%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

          The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

          Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...