Pop does not exist for NumPy arrays, but you can use NumPy indexing in conjunction with array restructuring like hstack / vstack or numpy.delete () to emulate popping.
Here are some examples of functions that I can come up with (which apparently don't work when the index is -1, but you can fix it with a simple conditional):
def poprow(my_array,pr): """ row popping in numpy arrays Input: my_array - NumPy array, pr: row index to pop out Output: [new_array,popped_row] """ i = pr pop = my_array[i] new_array = np.vstack((my_array[:i],my_array[i+1:])) return [new_array,pop] def popcol(my_array,pc): """ column popping in numpy arrays Input: my_array: NumPy array, pc: column index to pop out Output: [new_array,popped_col] """ i = pc pop = my_array[:,i] new_array = np.hstack((my_array[:,:i],my_array[:,i+1:])) return [new_array,pop]
This returns an array without a popup row / column, as well as a popup row / column separately:
>>> A = np.array([[1,2,3],[4,5,6]]) >>> [A,poparow] = poprow(A,0) >>> poparow array([1, 2, 3]) >>> A = np.array([[1,2,3],[4,5,6]]) >>> [A,popacol] = popcol(A,2) >>> popacol array([3, 6])