Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124188] Re: take square of the second and third column of a table
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Thu, 12 Jan 2012 04:18:59 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jel20o$lkl$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 1/11/2012 4:21 PM, hanciong awesome wrote:

>
> how can I take square of the 2nd and 3rd column?

I forgot to mention the simplest method, which is to square the slice
of the matrix directly.


tbl = {{1, 2, 3},{4, 5, 6},{7, 8, 9},{2, 3, 4}}

for second col:

tbl[[All, 2]]^2
-->{4, 25, 64, 9}

to do both cols at same time:

tbl[[All, {2, 3}]]^2
---> {{4, 9}, {25, 36}, {64, 81}, {9, 16}}

I like to Map allot, and so sometimes I overlook that it might not
be needed.

--Nasser







  • Prev by Date: import issue
  • Next by Date: Re: take square of the second and third column of a table
  • Previous by thread: Re: take square of the second and third column of a table
  • Next by thread: Re: take square of the second and third column of a table