numpy-equivalent of list.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]))

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

Above,

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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)