best way to take vertical slices from a matrix?

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Apr 26 05:08:27 EDT 2001


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


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list