Re: Can numpy do better than this?

2015-01-10 Thread Nobody
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)

Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 7:07:26 AM UTC+5:30, Ian wrote: > On Thu, Jan 8, 2015 at 6:13 PM, Rustom Mody wrote: > > With that I came up with the expression > > > > transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])])) > > > > Not exactly pretty. > > My hunch is it can be impr

Re: Can numpy do better than this?

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 6:13 PM, Rustom Mody wrote: > With that I came up with the expression > > transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])])) > > Not exactly pretty. > My hunch is it can be improved??... Hmm, you could use the column_stack constructor to avoid having

Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 6:43:45 AM UTC+5:30, Rustom Mody wrote: > On Friday, January 9, 2015 at 12:58:52 AM UTC+5:30, Ian wrote: > > On Thu, Jan 8, 2015 at 10:56 AM, 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 plac

Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 12:58:52 AM UTC+5:30, Ian wrote: > On Thu, Jan 8, 2015 at 10:56 AM, 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 a

Re: Can numpy do better than this?

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 10:56 AM, 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 transpose(mat): > return(

Can numpy do better than this?

2015-01-08 Thread Rustom Mody
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 transpose(mat): return([[l[i] for l in mat]for i in range(0,len(mat[0]))]) def rotate(mat):