[Numpy-discussion] generic slicing question

Neal Becker ndbecker2@gmail....
Fri Mar 4 08:19:29 CST 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