best way to take vertical slices from a matrix?

Olaf Delgado Friedrichs delgado at okeeffe-pc3.la.asu.edu
Fri Apr 27 08:47:51 EDT 2001


Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
>delgado at okeeffe-pc3.la.asu.edu (Olaf Delgado Friedrichs) wrote in 
><slrn9ecvsj.he1.delgado at okeeffe-pc3.la.asu.edu>:
>
>> If your rows can be tuples, you need something like
>> 
>>>>> def vslice(a,j):
>> ...   return apply(map, [None] + map(tuple, a))[j]
>> ...
>> 
>Surely a single map is sufficient to do everything the original question 
>asked?
>>>> print x
>[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
>>>> apply(map, (None,) + tuple(x))
>[(1, 4, 7), (2, 5, 8), (3, 6, 9)]

You are right, of course! I still get singleton tuples wrong,
occasionally, which might explain why I did not think of this variant.

Olaf



More information about the Python-list mailing list