Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7764

Re: take square of the second and third column of a table

From Tomas Garza <tgarza10@msn.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: take square of the second and third column of a table
Date 2012-01-12 09:22 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jem8oe$1cc$1@smc.vnet.net> (permalink)
References <201201112220.RAA22144@smc.vnet.net>

Show all headers | View raw


For example,
b = Table[RandomInteger[{0, 9}], {10}, {3}];(avoid capitalizing your variables to prevent conflicts with Mathematica's own symbols)
One possibility is as follows:
{#[[1]], #[[2]]^2, #[[3]]^2} & /@ b
This is functional programming, where you don't have t worry about table lengths and all that stuff.
-Tomas

> Date: Wed, 11 Jan 2012 17:20:16 -0500
> From: hanciong@gmail.com
> Subject: take square of the second and third column of a table
> To: mathgroup@smc.vnet.net
>
> 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


Thread

Re: take square of the second and third column of a table Tomas Garza <tgarza10@msn.com> - 2012-01-12 09:22 +0000

csiph-web