Re: matrix columns
- To: mathgroup at smc.vnet.net
- Subject: [mg30252] Re: [mg30247] matrix columns
- From: BobHanlon at aol.com
- Date: Sat, 4 Aug 2001 01:14:21 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/8/3 1:02:29 AM, aaurba2 at pop.uky.edu writes:
>According to the mathematica book there are 2 ways to access columns of
>a matrix (Mathmatica V. 3) Transpose[m][[i]] and Map[#[[i]]&,m]. Are
>the efficiencies of these two operations the same. Also, I can't figure
>out how you would assign a column in a matrix (i.e. set a column in the
>matrix equal to a specific vector or something). The two previously
>mentioned functions return copies of the columns in the m and you can't
>assign a new value to it as far as I can see. Is this possible?
>
$Version
"4.1 for Power Macintosh (November \
2, 2000)"
m = Table[Range[1000], {500}];
n = 6;
Timing[Union[Transpose[m][[n]]] == {n}]
{0.31666666666660603*Second, True}
Timing[Union[Map[#[[n]]&, m]] == {n}]
{0.033333333333416704*Second, True}
Timing[Union[m[[All, n]]] == {n}]
{0.*Second, True}
m[[All, n]] == Map[#[[n]]&, m] == Transpose[m][[n]]
True
m = Table[Range[5], {3}];
m[[All, 2]] = 20;
m
{{1, 20, 3, 4, 5}, {1, 20, 3, 4,
5}, {1, 20, 3, 4, 5}}
m[[All, 2]] = {a, b, c};
m
{{1, a, 3, 4, 5}, {1, b, 3, 4, 5},
{1, c, 3, 4, 5}}
Bob Hanlon
Chantilly, VA USA