Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83382

Re: Can numpy do better than this?

References <71ecb9ec-5d8c-4503-a75b-1d4aeca79b08@googlegroups.com> <mailman.17484.1420745315.18130.python-list@python.org> <719d2a22-6c41-467c-a046-0a53704953c6@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-01-08 18:36 -0700
Subject Re: Can numpy do better than this?
Newsgroups comp.lang.python
Message-ID <mailman.17492.1420767434.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jan 8, 2015 at 6:13 PM, Rustom Mody <rustompmody@gmail.com> 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]])

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can numpy do better than this? Rustom Mody <rustompmody@gmail.com> - 2015-01-08 09:56 -0800
  Re: Can numpy do better than this? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-08 12:27 -0700
    Re: Can numpy do better than this? Rustom Mody <rustompmody@gmail.com> - 2015-01-08 17:13 -0800
      Re: Can numpy do better than this? Rustom Mody <rustompmody@gmail.com> - 2015-01-08 17:19 -0800
      Re: Can numpy do better than this? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-08 18:36 -0700
        Re: Can numpy do better than this? Rustom Mody <rustompmody@gmail.com> - 2015-01-08 17:45 -0800
  Re: Can numpy do better than this? Nobody <nobody@nowhere.invalid> - 2015-01-11 04:12 +0000

csiph-web