Select column from a list

Piet van Oostrum piet at
Fri Aug 28 15:23:47 CEST 2009

>>>>> hoffik <beorn at> (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>
URL: [PGP 8DAE142BE17999C4]
Private email: piet at

More information about the Python-list mailing list