best way to take vertical slices from a matrix?

John J. Lee phrxy at csv.warwick.ac.uk
Tue Apr 24 19:45:37 EDT 2001


On Wed, 25 Apr 2001, mary wrote:

> 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)
[...]

If you have a lot of data, or are doing complicated stuff like this, the
Numeric module.  Otherwise, use lists of lists and a loop, I guess, and
make an interface of whatever form takes your fancy.


John




More information about the Python-list mailing list