Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; '21,': 0.07; '22,': 0.09; '34,': 0.09; '40,': 0.09; 'constructor': 0.09; 'jan': 0.12; '23,': 0.16; '24],': 0.16; '32,': 0.16; '33,': 0.16; '39,': 0.16; 'array.': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; '15,': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'skip:t 40': 0.33; 'could': 0.34; 'received:google.com': 0.35; '14,': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'skip:n 30': 0.60; 'subject:Can': 0.60; '20,': 0.68; '26,': 0.68; 'subject:this': 0.83; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=+x4cof64npFKI3Vk1VQC2Fs7pyoaTIpTzoDNj84YQec=; b=LTz7AZeMV+c8sXhKc5q2pawbim67BNUwT6U1Zgx2XM03c9LOqEZdJTDard7/G+QYxB Z6lbQmMHtjf5HDVUbN98HPNS89llsCWV0WFFX/xI/DzezOB9sGqQnhxvv7V4tjtCJD/5 +o0iOGCD6OOWCMrKdr7yMHvLJTQUCP54eX5R0e3oAnHWfFIt96K0ZGU5Af7GFt1k4tXp Rg+R7j9BHwms7k3UcVRpLffNPnGhGCSv+f8i+Hwy5OUaQida9wjYWx70DcPouUJhhVPw iXwvIUIINlGBmJuimVip5D+w7d89MslzlZ7qIds0kmPbeYipZT73V6s/lihoQdYp5Eoy HOYw== X-Received: by 10.68.222.130 with SMTP id qm2mr19933221pbc.44.1420767423725; Thu, 08 Jan 2015 17:37:03 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <719d2a22-6c41-467c-a046-0a53704953c6@googlegroups.com> References: <71ecb9ec-5d8c-4503-a75b-1d4aeca79b08@googlegroups.com> <719d2a22-6c41-467c-a046-0a53704953c6@googlegroups.com> From: Ian Kelly Date: Thu, 8 Jan 2015 18:36:23 -0700 Subject: Re: Can numpy do better than this? To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420767434 news.xs4all.nl 2869 [2001:888:2000:d::a6]:38806 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83382 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]])