Can numpy do better than this?

Nobody nobody at nowhere.invalid
Sat Jan 10 23:12:54 EST 2015


On Thu, 08 Jan 2015 09:56:50 -0800, Rustom Mody wrote:

> Given a matrix I want to shift the 1st column 0 (ie leave as is) 2nd by
> one place, 3rd by 2 places etc.
> 
> This code works.
> But I wonder if numpy can do it shorter and simpler.

def shiftcols(mat):
    iy,ix = np.indices(mat.shape)
    return mat[(iy+ix)%mat.shape[0],ix]




More information about the Python-list mailing list