<bdo id='BvkJC'></bdo><ul id='BvkJC'></ul>
<legend id='BvkJC'><style id='BvkJC'><dir id='BvkJC'><q id='BvkJC'></q></dir></style></legend>

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

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

      <tfoot id='BvkJC'></tfoot>

      1. ndarray 比 recarray 访问快吗?

        时间:2023-09-27

          • <bdo id='MuEaV'></bdo><ul id='MuEaV'></ul>
          • <small id='MuEaV'></small><noframes id='MuEaV'>

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

                • 本文介绍了ndarray 比 recarray 访问快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我能够将我的 recarray 数据复制到 ndarray,进行一些计算并返回带有更新值的 ndarray.

                  I was able to copy my recarray data to a ndarray, do some calculations and return the ndarray with updated values.

                  然后,我在 numpy.lib.recfunctions 中发现了 append_fields() 功能,并认为将 2 个字段简单地附加到我原来的 recarray 会更聪明保存我的计算值.

                  Then, I discovered the append_fields() capability in numpy.lib.recfunctions, and thought it would be a lot smarter to simply append 2 fields to my original recarray to hold my calculated values.

                  当我这样做时,我发现操作要慢得多.我不需要计时,基于 ndarray 的过程需要几秒钟,而使用 recarray 需要一分钟以上,而且我的测试数组很小,<10,000 行.

                  When I did this, I found the operation was much, much slower. I didn't have to time it, the ndarray based process takes a few seconds compared to a minute+ with recarray and my test arrays are small, <10,000 rows.

                  这是典型的吗?ndarray 访问比 recarray 快得多?我预计会由于按字段名称访问而导致性能下降,但不会这么严重.

                  Is this typical? ndarray access is much faster than recarray? I expected some performance degradation due to access by field name, but not this much.

                  推荐答案

                  2018 年 11 月 15 日更新
                  我扩展了我的时序测试,以阐明 ndarray、结构化数组、recarray 和掩码数组(记录数组的类型?)的性能差异.每个都有细微的差别.请参阅此处的讨论:
                  numpy-discussion:structured-arrays-recarrays-and-record-arrays

                  这是我的性能测试结果.我构建了一个非常简单的示例(使用我的 HDF5 数据集之一)来比较存储在 4 种类型数组中的相同数据的性能:ndarray、结构化数组、recarray 和掩码数组.在构造数组之后,它们被传递给一个函数,该函数简单地遍历每一行并从每一行中提取 12 个值.这些函数从 timeit 函数调用一次(数字=1).该测试只测量数组读取函数,并避免所有其他计算.
                  下面给出了 9,000 行的结果:

                  Here are result of my performance tests. I built a very simple example (using 1 of my HDF5 data sets) to compare performance with the same data stored in 4 types of arrays: ndarray, structured array, recarray and masked array. After the arrays are constructed, they are passed to a function that simply loops thru each row and extracts 12 values from each row. The functions are called from the timeit function with a single pass (number=1). This test only measures the array read function, and avoids all other calculations.
                  Results given below for 9,000 rows:

                  for ndarray: 0.034137165047070615
                  for structured array: 0.1306827116913577
                  for recarray: 0.446010040784266
                  for masked array: 31.33269560998199
                  

                  根据此测试,访问性能随每种类型而降低.结构化数组和 recarray 的访问时间比 ndarray 访问慢 4 到 13 倍(但都只有几分之一秒).但是,ndarray 访问比掩码数组访问快 1000 倍.这解释了我在完整示例中看到的秒到分钟的差异.希望这些数据对遇到此问题的其他人有用.

                  Based on this test, access performance decreases with each type. Access times for structured array and recarray are 4x-13x slower than ndarray access (but all are only a fraction of second). However, ndarray access is 1000x faster than masked array access. That explains the seconds to minutes difference I see in my complete example. Hopefully this data is useful to others that encounter this issue.

                  这篇关于ndarray 比 recarray 访问快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 numpy 中创建一个“接受"附加的空列表网格? 下一篇:如何使用 Python 将 xml 文件属性附加到数组值?

                  相关文章

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

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

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