MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: making a column into a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23050] Re: [mg22990] Re: [mg22964] making a column into a list
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 13 Apr 2000 02:43:33 -0400 (EDT)
  • References: <LP9J4.62$UI4.3344@ralph.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mark,

Thanks for bringing this to my attention.
We can get a flat list directly:

mat = {{1, 2, 3}, {4, 5, 6}};

mat[[All, 2]]

        {2, 5}

The brackets also allow quit a bit of construction:

mat[[{2, 1, 1}, {2, 1, 2}]]

        {{5, 4, 5}, {2, 1, 2}, {2, 1, 2}}

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

"Mark Harder" <harderm at ucs.orst.edu> wrote in message
news:LP9J4.62$UI4.3344 at ralph.vnet.net...
> 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: [mg23050] [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
> >
> >
> >
> >
> >
> >
>
>
>




  • Prev by Date: Re: Help! Mathematica on my 500MHz outperforms my GHz machine!
  • Next by Date: Re: Speeding up Inverting matrices.
  • Previous by thread: Re: Re: making a column into a list
  • Next by thread: uninstalling mathreader