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


Groups > comp.lang.python > #37897

Re: numpy array operation

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'advance.': 0.15; 'result.': 0.15; '2],': 0.16; '3],': 0.16; '[2,': 0.16; 'iterator,': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'row': 0.16; 'subject:array': 0.16; 'wrote:': 0.17; 'jan': 0.18; '>>>': 0.18; 'equivalent': 0.20; 'import': 0.21; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:[ 10': 0.26; 'regular': 0.27; 'header:X -Complaints-To:1': 0.28; '>>>>': 0.29; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'replaced': 0.35; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'first': 0.61; '2013': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: numpy array operation
Date Tue, 29 Jan 2013 15:05:09 -0500
References <f94d7654-2b87-404b-a0b0-76f1ccf8ee6c@googlegroups.com> <ke95jk$v42$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <ke95jk$v42$1@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1192.1359489934.2939.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359489934 news.xs4all.nl 6868 [2001:888:2000:d::a6]:58784
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37897

Show key headers only | View raw


On 1/29/2013 1:49 PM, Alok Singhal wrote:
> On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote:
>
>> Is there a numpy operation that does the following to the array?
>>
>> 1 2  ==>  4 3
>> 3 4       2 1
>>
>> Thanks in advance.
>
> How about:
>
>>>> import numpy as np
>>>> a = np.array([[1,2],[3,4]])
>>>> a
> array([[1, 2], [3, 4]])
>>>> a[::-1, ::-1]
> array([[4, 3], [2, 1]])
>

Nice. The regular Python equivalent is

a = [[1,2],[3,4]]
print([row[::-1] for row in a[::-1]])
 >>>
[[4, 3], [2, 1]]

The second slice can be replaced with reversed(a), which returns an 
iterator, to get
[row[::-1] for row in reversed(a)]
The first slice would have to be list(reversed(a)) to get the same result.

-- 
Terry Jan Reedy

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


Thread

numpy array operation "C. Ng" <ngcbmy@gmail.com> - 2013-01-29 00:41 -0800
  Re: numpy array operation Peter Otten <__peter__@web.de> - 2013-01-29 10:28 +0100
  Re: numpy array operation Tim Williams <tjandacw@cox.net> - 2013-01-29 04:59 -0800
  Re: numpy array operation Alok Singhal <as8ca@virginia.edu> - 2013-01-29 18:49 +0000
    Re: numpy array operation Terry Reedy <tjreedy@udel.edu> - 2013-01-29 15:05 -0500

csiph-web