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


Groups > comp.lang.python > #105534

Re: numpy arrays

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: numpy arrays
Date 2016-03-23 21:35 +1100
Message-ID <mailman.43.1458729342.2244.python-list@python.org> (permalink)
References <3774dc9b-f9d3-462b-bbe4-41b8b2244db7@googlegroups.com>

Show all headers | View raw


On Wed, Mar 23, 2016 at 9:06 PM, Heli <hemla21@gmail.com> wrote:
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
>  [1,2,3,4],
>  [1,2,3,4]
>  [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
>  [2,2,2,2]
>  [3,3,3,3]
>  [4,4,4,4]]

What you want is called *transposing* the array:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html

That should be a sufficiently fast operation.

ChrisA

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


Thread

numpy arrays Heli <hemla21@gmail.com> - 2016-03-23 03:06 -0700
  Re: numpy arrays Steven D'Aprano <steve@pearwood.info> - 2016-03-23 21:32 +1100
  Re: numpy arrays Chris Angelico <rosuav@gmail.com> - 2016-03-23 21:35 +1100
    Re: numpy arrays Nobody <nobody@nowhere.invalid> - 2016-03-23 13:45 +0000
      Re: numpy arrays Heli <hemla21@gmail.com> - 2016-04-06 09:26 -0700
        Re: numpy arrays Heli <hemla21@gmail.com> - 2016-04-07 07:31 -0700
          Re: numpy arrays Heli <hemla21@gmail.com> - 2016-04-11 02:17 -0700
          Re: numpy arrays Heli <hemla21@gmail.com> - 2016-04-11 02:32 -0700
  Re: numpy arrays Manolo Martínez <manolo@austrohungaro.com> - 2016-03-23 11:26 +0100
  Re: numpy arrays Heli <hemla21@gmail.com> - 2016-03-23 03:47 -0700
  Re: numpy arrays Simon Ward <simon+python@bleah.co.uk> - 2016-03-23 10:47 +0000

csiph-web