I have a function:
remove_last(x):
if x is a 1D vector, then I want it to remove the last element in it. sometime x may be the matrix of such a vector from which I want to remove the last element. In this case, I need to delete the last column.
Usage example:
aa = np.asarray([1,2,3]) print remove_last(aa)
So far, I:
def remove_last(x): assert(x.ndim<=2) if x.ndim==1: return x[:-1] else: return x[:,:-1]
which works, but it's not very nice.
There must be a better way using the famous numpy chopping mechanic
source share