Can numpy do better than this?
Rustom Mody
rustompmody at gmail.com
Thu Jan 8 20:45:34 EST 2015
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 improved??...
>
> Hmm, you could use the column_stack constructor to avoid having to
> transpose the array.
>
> >>> np.column_stack(np.roll(mat[:,i],i,0) for i in range(mat.shape[1]))
> array([[ 1, 38, 33, 28, 23, 18],
> [ 7, 2, 39, 34, 29, 24],
> [13, 8, 3, 40, 35, 30],
> [19, 14, 9, 4, 41, 36],
> [25, 20, 15, 10, 5, 42],
> [31, 26, 21, 16, 11, 6],
> [37, 32, 27, 22, 17, 12]])
You are my sweetheart!
Removing Javaish-dot-noise:
column_stack(roll(mat[:,i],i,0) for i in range(mat.shape[1]))
More information about the Python-list
mailing list