Select column from a list
Piet van Oostrum
piet at cs.uu.nl
Fri Aug 28 09:23:47 EDT 2009
>>>>> hoffik <beorn at seznam.cz> (h) wrote:
>h> Hello,
>h> I'm quite new in Python and I have one question. I have a 2D matrix of
>h> values stored in list (3 columns, many rows). I wonder if I can select one
>h> column without having to go through the list with 'for' command.
>h> For example I have list called 'values'.
>h> When I write 'values[0]' or 'values[0][:]' I'll get the first row.
>h> But when I write 'values[:][0]' I won't get the first column, but the first
>h> row again! I can't see why.
If you work with matrices, numpy may be interesting for you. It does
have the required functionality: M[:,0] will give you the first column.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list