Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7763
| From | Barrie Stokes <Barrie.Stokes@newcastle.edu.au> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: take square of the second and third column of a table |
| Date | 2012-01-12 09:21 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jem8nf$1c6$1@smc.vnet.net> (permalink) |
| References | <201201112220.RAA22144@smc.vnet.net> |
Hi
I like to use code that I think is explicit, i.e., I can see what I was doing when I read my code in 6 months time.
A = {{a, b, c}, {d, e, f}, {g, h, i}, {j, k, l}}
A // Column
B = Table[{A[[n]][[1]], A[[n]][[2]]^2, A[[n]][[3]]^2}, {n, 1, 4}]
Map[ (s \[Function] {
\!\(\*SubscriptBox[\(s\), \(\(\[LeftDoubleBracket]\)\(1\)\(\ \)\(\
\[RightDoubleBracket]\)\)]\),
\!\(\*SubscriptBox[\(s\), \(\(\[LeftDoubleBracket]\)\(\ \)\(2\)\(\ \)\
\(\[RightDoubleBracket]\)\)]\)^2,
\!\(\*SubscriptBox[\(s\), \(\(\[LeftDoubleBracket]\)\(\ \)\(3\)\(\ \)\
\(\[RightDoubleBracket]\)\)]\)^2}), A ]
Barrie
PS
Always a bad idea to use capitals for or as the first character of your variables; try C = 34.
>>> On 12/01/2012 at 9:20 am, in message <201201112220.RAA22144@smc.vnet.net>,
hanciong awesome <hanciong@gmail.com> wrote:
> Hello, suppose I have a very long table like this:
>
> 1 2 3
> 4 5 6
> 7 8 9
> .......
> 2 3 4
>
> how can I take square of the 2nd and 3rd column? I always do it by
> making a new table. so let's say the above table is A and it has 100
> lines, then I make the new table as the following:
>
> B=Table[{A[[n]][[1]],A[[n]][[2]]^2,A[[n]][[3]]^2},{n,1,100}]
>
> But if the length of the table is unknown, this way is impractical.
> Could anyone suggests better way? thank you
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: take square of the second and third column of a table Barrie Stokes <Barrie.Stokes@newcastle.edu.au> - 2012-01-12 09:21 +0000
csiph-web