<small id='mEiNl'></small><noframes id='mEiNl'>

      <i id='mEiNl'><tr id='mEiNl'><dt id='mEiNl'><q id='mEiNl'><span id='mEiNl'><b id='mEiNl'><form id='mEiNl'><ins id='mEiNl'></ins><ul id='mEiNl'></ul><sub id='mEiNl'></sub></form><legend id='mEiNl'></legend><bdo id='mEiNl'><pre id='mEiNl'><center id='mEiNl'></center></pre></bdo></b><th id='mEiNl'></th></span></q></dt></tr></i><div id='mEiNl'><tfoot id='mEiNl'></tfoot><dl id='mEiNl'><fieldset id='mEiNl'></fieldset></dl></div>

      • <bdo id='mEiNl'></bdo><ul id='mEiNl'></ul>
    1. <legend id='mEiNl'><style id='mEiNl'><dir id='mEiNl'><q id='mEiNl'></q></dir></style></legend>

      <tfoot id='mEiNl'></tfoot>

        Python 和 Numpy 的 nan 和 set

        时间:2023-07-03
      1. <i id='N1Of9'><tr id='N1Of9'><dt id='N1Of9'><q id='N1Of9'><span id='N1Of9'><b id='N1Of9'><form id='N1Of9'><ins id='N1Of9'></ins><ul id='N1Of9'></ul><sub id='N1Of9'></sub></form><legend id='N1Of9'></legend><bdo id='N1Of9'><pre id='N1Of9'><center id='N1Of9'></center></pre></bdo></b><th id='N1Of9'></th></span></q></dt></tr></i><div id='N1Of9'><tfoot id='N1Of9'></tfoot><dl id='N1Of9'><fieldset id='N1Of9'></fieldset></dl></div>
          <tbody id='N1Of9'></tbody>

              <tfoot id='N1Of9'></tfoot>

              <small id='N1Of9'></small><noframes id='N1Of9'>

                <bdo id='N1Of9'></bdo><ul id='N1Of9'></ul>

                  <legend id='N1Of9'><style id='N1Of9'><dir id='N1Of9'><q id='N1Of9'></q></dir></style></legend>

                  本文介绍了Python 和 Numpy 的 nan 和 set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 Python 的 Numpy、set 和 NaN(非数字)时遇到了无法预料的行为:

                  I ran into an unpredicted behavior with Python's Numpy, set and NaN (not-a-number):

                  >>> set([np.float64('nan'), np.float64('nan')])
                  set([nan, nan])
                  >>> set([np.float32('nan'), np.float32('nan')])
                  set([nan, nan])
                  >>> set([np.float('nan'), np.float('nan')])
                  set([nan, nan])
                  >>> set([np.nan, np.nan])
                  set([nan])
                  >>> set([float('nan'), float('nan')])
                  set([nan, nan])
                  

                  这里 np.nan 产生单个元素集,而 Numpy 的 nan 产生一个集合中的多个 nan.float('nan') 也是如此!请注意:

                  Here np.nan yields a single element set, while Numpy's nans yield multiple nans in a set. So does float('nan')! And note that:

                  >>> type(float('nan')) == type(np.nan)
                  True
                  

                  我想知道这种差异是如何产生的,不同行为背后的合理性是什么.

                  I wonder how this difference come about and what the rationality is behind the different behaviors.

                  推荐答案

                  NAN 的一个属性是 NAN != NAN,与所有其他数字不同.但是,set 的实现首先检查 id(x) 是否与哈希索引处的现有成员匹配,然后再尝试插入新成员.如果您有两个具有不同 id 且都具有值 NAN 的对象,您将在集合中获得两个条目.如果它们都具有相同的 id,则它们会折叠成一个条目.

                  One of the properties of NAN is that NAN != NAN, unlike all other numbers. However, the implementation of set first checks to see if id(x) matches the existing member at a hash index before it tries to insert a new one. If you have two objects with different ids that both have the value NAN, you'll get two entries in the set. If they both have the same id, they collapse into a single entry.

                  正如其他人指出的那样,np.nan 是一个始终具有相同 id 的单个对象.

                  As pointed out by others, np.nan is a single object that will always have the same id.

                  这篇关于Python 和 Numpy 的 nan 和 set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python:带有生成器的给定集合的幂集 下一篇:设置与frozenset 性能

                  相关文章

                • <legend id='eeUAU'><style id='eeUAU'><dir id='eeUAU'><q id='eeUAU'></q></dir></style></legend>
                  <tfoot id='eeUAU'></tfoot>

                  1. <i id='eeUAU'><tr id='eeUAU'><dt id='eeUAU'><q id='eeUAU'><span id='eeUAU'><b id='eeUAU'><form id='eeUAU'><ins id='eeUAU'></ins><ul id='eeUAU'></ul><sub id='eeUAU'></sub></form><legend id='eeUAU'></legend><bdo id='eeUAU'><pre id='eeUAU'><center id='eeUAU'></center></pre></bdo></b><th id='eeUAU'></th></span></q></dt></tr></i><div id='eeUAU'><tfoot id='eeUAU'></tfoot><dl id='eeUAU'><fieldset id='eeUAU'></fieldset></dl></div>

                      <small id='eeUAU'></small><noframes id='eeUAU'>

                        <bdo id='eeUAU'></bdo><ul id='eeUAU'></ul>