Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37897
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: numpy array operation |
| Date | 2013-01-29 15:05 -0500 |
| References | <f94d7654-2b87-404b-a0b0-76f1ccf8ee6c@googlegroups.com> <ke95jk$v42$1@dont-email.me> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1192.1359489934.2939.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Find similar | Unroll 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