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

      list.pop 的 numpy 等效项?

      时间:2023-09-27

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

                <tbody id='GnfYQ'></tbody>

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

                本文介绍了list.pop 的 numpy 等效项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否有一个 numpy 方法等效于 python 列表的内置 pop 方法?

                Is there a numpy method which is equivalent to the builtin pop for python lists?

                Popping 显然不适用于 numpy 数组,我想避免列表转换.

                Popping obviously doesn't work on numpy arrays, and I want to avoid a list conversion.

                推荐答案

                NumPy 数组没有 pop 方法,但你可以只使用基本切片(这会很有效,因为它返回一个视图,而不是副本):

                There is no pop method for NumPy arrays, but you could just use basic slicing (which would be efficient since it returns a view, not a copy):

                In [104]: y = np.arange(5); y
                Out[105]: array([0, 1, 2, 3, 4])
                
                In [106]: last, y = y[-1], y[:-1]
                
                In [107]: last, y
                Out[107]: (4, array([0, 1, 2, 3]))
                

                如果有 pop 方法,它将返回 y 中的 last 值并修改 y.

                If there were a pop method it would return the last value in y and modify y.

                以上,

                last, y = y[-1], y[:-1]
                

                将最后一个值赋给变量last并修改y.

                assigns the last value to the variable last and modifies y.

                这篇关于list.pop 的 numpy 等效项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:pandas:删除重复行,同时保留虚拟变量值 下一篇:如何增加python中的堆栈大小

                相关文章

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

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

                1. <small id='Zrh7b'></small><noframes id='Zrh7b'>

                    • <bdo id='Zrh7b'></bdo><ul id='Zrh7b'></ul>