python: numpy-equivalent of list.pop?
<p>Is there a numpy method which is equivalent to the builtin <code>pop</code> for python lists? popping obviously doenst work on numpy arrays, and I want to avoid a list conversion.</p>

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

<pre><code>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]))
</code></pre>

<p>If there were a <code>pop</code> method it would return the <code>last</code> value in <code>y</code> and modify <code>y</code>.</p>

<p>Above, </p>

<pre><code>last, y = y[-1], y[:-1]
</code></pre>

<p>assigns the last value to the variable <code>last</code> and modifies <code>y</code>.</p>

python arrays list numpy pop