best way to take vertical slices from a matrix?

waldekO osuchw at ecn.ab.ca.remove_me
Thu Apr 26 09:43:39 EDT 2001


mary <mary.stern at virgin.net> wrote in message
news:9c50pc$5vtg$1 at sp15at20.hursley.ibm.com...
> I have a simple problem and am interested to find
> the 'best' way to do this in python:
>
> Given a list such as:
>
> x[0] = (1,2,3)
> x[1] = (4,5,6)
> x[2] = (7,8,9)
>
> what's the best way to 'take vertical slices' from this
> matrix, ie end up with:
>
> y[0] = (1,4,7)
> y[1] = (2,5,8)
> y[2] = (3,6,9)
>
> Cheers!
> Tushar.
>
>
one more way of doing it:

>>> x
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
>>> y = apply(zip,x)
>>> y
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]

waldekO





More information about the Python-list mailing list