Matrix (list-in-list), how to get a column?
F. Petitjean
littlejohn.75 at noos.fr
Thu Oct 21 11:46:45 EDT 2004
On Thu, 21 Oct 2004 17:19:04 +0200, Arvid Andersson <arvid at linux.se> wrote:
>
> I have some data that looks like this:
> data = [[1, 2], [3, 4], [5, 6]]
>
> I want to send columns 1 and 2 to a function
> as two variables, say "plot(col1,col2)".
>
>From a interpreter session :
>>> data = [[1, 2], [3, 4], [5, 6]]
>>> col1 = [ pt[0] for pt in data ]
>>> col1
[1, 3, 5]
>>> import Numeric as N
>>> N.array(data)
array([[1, 2],
[3, 4],
[5, 6]])
>>> N.array(data, N.Float)
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
>>> pts = N.array(data, N.Float)
>>> pts[:,0]
array([ 1., 3., 5.])
Hope that helps. Don't hesitate to try directly at the interpreter
prompt.
More information about the Python-list
mailing list