Re: Re: making a column into a list
- To: mathgroup at smc.vnet.net
- Subject: [mg23016] Re: [mg22990] Re: [mg22964] making a column into a list
- From: "Mark Harder" <harderm at ucs.orst.edu>
- Date: Tue, 11 Apr 2000 23:18:33 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Allan;
Thanks for the suggestion to use Part to extract a column from a matrix;
it is indeed simpler and faster when you want to keep the extracted column
in column-vector form. To get a flat list from your result, requires that
TakeColumn be followed by Flatten[].
I must confess that this aspect of Mathematica -- the correspondences
between "vector" and "list" and "matrix" and "2-dimensional list"-- is
still a bit confusing to me, so let me run through my reasoning. The result
that you obtained with TakeColumns[], remains in the form of a column matrix
(list of single-element lists), and I was attempting to produce a "list", as
per the poster's request, which I interpreted to be a singly dimensioned
list, which I thought corresponded to a row-vector from some matrix. To see
how this latter is incorrect, I now note the difference between using
Flatten and Transpose:
In[6]:=Flatten[{{1}, {1}, {1}} ]
Out[6]={1, 1, 1}
, a flat list.
In[7]:=Transpose[{{1}, {1}, {1}} ]
Out[7]={{1, 1, 1}}
, a list-of-lists, or a one-by-three matrix.
In working out my posting, I used Column[], from the
Statistics`DataManipulation` package, which I had forgotten was loaded at
the time. Sorry I did not mention that; details, details....
-mark harder
harderm at ucs.orst.edu
-----Original Message-----
From: Allan Hayes <hay at haystack.demon.co.uk>
To: mathgroup at smc.vnet.net
Subject: [mg23016] [mg22990] Re: [mg22964] making a column into a list
>Mark:
>You report
>> To get a column from a matrix in list form:
>> IN>
>> matrix = {{1, 2}, {1, 2}, {1, 2}}
>> column = Column[matrix, 1]
>> OUT>
>> {{1, 2}, {1, 2}, {1, 2}}
>> {1, 1, 1}
>
>This doesn't work for me with Mathematica 4.0.
>
>matrix = {{1, 2}, {1, 2}, {1, 2}}
>column = Column[matrix, 1]
>
>{{1, 2}, {1, 2}, {1, 2}}
>
>Column[{{1, 2}, {1, 2}, {1, 2}}, 1]
>
>Did you mean TakeColumns from the package?
>
><< LinearAlgebra`MatrixManipulation`
>
>TakeColumns[matrix, {1}]
>
> {{1}, {1}, {1}}
>
>-------------------------------------
>
>But in Mathematica 4.0 we can use
>
>matrix[[All, {1}]]
>
>{{1}, {1}, {1}}
>
>And this is much faster:
>
>matrix = Table[Random[], {50000}, {10}];
>
>TakeColumns[matrix, {1}]; // Timing
>
>{1.37 Second, Null}
>
>matrix[[All, {1}]]; // Timing
>
>{0.11 Second, Null}
>
>
>--
>Allan
>---------------------
>Allan Hayes
>Mathematica Training and Consulting
>Leicester UK
>www.haystack.demon.co.uk
>hay at haystack.demon.co.uk
>Voice: +44 (0)116 271 4198
>Fax: +44 (0)870 164 0565
>
>
>
>
>
>