[Numpy-discussion] generic slicing question

Neal Becker ndbecker2 at gmail.com
Fri Mar 4 09:19:29 EST 2011

This will subtract col 0 from all cols of a 2-d array:

# subtract col 0 from all cols
def ll2llr (m):
    return m - m[:,0][:,np.newaxis]

In general, how to subtract the (n-1)d slice at index 0 from all elements of an 
n-d array?

(I think a 3d version is:
m - m[:,:,0][:,:,np.newaxis]

More information about the NumPy-Discussion mailing list