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

  • <small id='ku1nI'></small><noframes id='ku1nI'>

      <tfoot id='ku1nI'></tfoot>
        • <bdo id='ku1nI'></bdo><ul id='ku1nI'></ul>
      1. Python:使 numpy 默认为 float32

        Python: Making numpy default to float32(Python:使 numpy 默认为 float32)

          <bdo id='0s77D'></bdo><ul id='0s77D'></ul>
                <tbody id='0s77D'></tbody>
              <tfoot id='0s77D'></tfoot>

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

              <legend id='0s77D'><style id='0s77D'><dir id='0s77D'><q id='0s77D'></q></dir></style></legend>
                1. <small id='0s77D'></small><noframes id='0s77D'>

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

                  问题描述

                  是否有任何干净的方法可以将 numpy 设置为全局使用 float32 值而不是 float64?

                  Is there any clean way of setting numpy to use float32 values instead of float64 globally?

                  推荐答案

                  我不知道.您要么需要在调用任何数组的构造函数时显式指定 dtype,要么在将数组传递给 GPU 代码之前将数组强制转换为 float32(使用 ndarray.astype 方法)(我认为这就是问题所在?).如果是你真正担心的 GPU 案例,我更喜欢后者——如果没有非常透彻地了解 numpy 广播规则和非常精心设计的代码,尝试将所有内容保持在单精度状态会变得非常烦人.

                  Not that I am aware of. You either need to specify the dtype explicitly when you call the constructor for any array, or cast an array to float32 (use the ndarray.astype method) before passing it to your GPU code (I take it this is what the question pertains to?). If it is the GPU case you are really worried about, I favor the latter - it can become very annoying to try and keep everything in single precision without an extremely thorough understanding of the numpy broadcasting rules and very carefully designed code.

                  另一种选择可能是创建自己的方法来重载标准 numpy 构造函数(如 numpy.zeros、numpy.ones、numpy.empty).这应该非常接近于将所有内容都保存在 float32 中.

                  Another alternative might be to create your own methods which overload the standard numpy constructors (so numpy.zeros, numpy.ones, numpy.empty). That should go pretty close to keeping everything in float32.

                  这篇关于Python:使 numpy 默认为 float32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                    • <legend id='ggkD4'><style id='ggkD4'><dir id='ggkD4'><q id='ggkD4'></q></dir></style></legend>

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

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